1
0
mirror of https://gitlab.os-k.eu/os-k-team/kvisc.git synced 2023-08-25 14:05:46 +02:00
kvisc/ka/str/strrev.k
2019-06-06 22:07:34 +02:00

74 lines
1.0 KiB
Plaintext

; The OS/K Team licenses this file to you under the MIT license.
; See the LICENSE file in the project root for more information.
;
; void strrev(char *buf, const char *str)
;
; buf and src must NOT overlap
;
strrev:
test b[ax1], b[ax1]
mov.z b[ax0], 0
ret.z
; save str's location
mov rdx, ax1
; go to str's end, just before
; the null terminator
.1:
test b[ax1+1], b[ax1+1]
inc.nz ax1
jmp.nz .1
.2:
; copy, going backward though str
; and forward through buf
mov b[ax0], b[ax1]
cmp ax1, rdx
mov.z b[ax0+1], 0
ret.z
inc ax0
dec ax1
jmp .2
;
; void strrev2(char *str)
;
; Inverses str
;
strrev2:
test b[ax0], b[ax0]
ret.z
mov ax1, ax0
; go to str's end, just before
; the null terminator
.1:
test b[ax1+1], b[ax1+1]
inc.nz ax1
jmp.nz .1
; increase ax0 while decreasing ax1, performing exchanges
.2:
cmp ax0, ax1
jmp.ae .3
xchg b[ax0], b[ax1]
inc ax0
dec ax1
jmp .2
.3:
ret