kvisc/ka/crt/str/strrev.k

74 lines
1.0 KiB
Plaintext
Raw Normal View History

2019-05-30 18:31:50 +02:00
; 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)
;
2019-06-05 22:59:32 +02:00
; buf and src must NOT overlap
;
2019-05-30 18:31:50 +02:00
strrev:
test b[ax1], b[ax1]
2019-06-06 22:07:34 +02:00
mov.z b[ax0], 0
ret.z
2019-05-30 18:31:50 +02:00
2019-05-30 18:36:06 +02:00
; save str's location
2019-06-15 20:21:38 +02:00
mov lx0, ax1
2019-05-30 18:36:06 +02:00
2019-05-30 19:07:04 +02:00
; go to str's end, just before
; the null terminator
2019-05-30 18:31:50 +02:00
.1:
test b[ax1+1], b[ax1+1]
2019-06-06 22:07:34 +02:00
inc.nz ax1
jmp.nz .1
2019-05-30 18:31:50 +02:00
2019-05-30 20:23:27 +02:00
.2:
2019-05-30 19:07:04 +02:00
; copy, going backward though str
2019-05-30 19:33:22 +02:00
; and forward through buf
2019-05-30 18:31:50 +02:00
mov b[ax0], b[ax1]
2019-06-15 20:21:38 +02:00
cmp ax1, lx0
2019-06-06 22:07:34 +02:00
mov.z b[ax0+1], 0
ret.z
2019-05-30 18:31:50 +02:00
inc ax0
dec ax1
jmp .2
2019-06-05 22:59:32 +02:00
;
; void strrev2(char *str)
;
; Inverses str
;
strrev2:
test b[ax0], b[ax0]
2019-06-06 22:07:34 +02:00
ret.z
2019-06-05 22:59:32 +02:00
mov ax1, ax0
; go to str's end, just before
; the null terminator
.1:
test b[ax1+1], b[ax1+1]
2019-06-06 22:07:34 +02:00
inc.nz ax1
jmp.nz .1
2019-06-05 22:59:32 +02:00
; increase ax0 while decreasing ax1, performing exchanges
.2:
cmp ax0, ax1
2019-06-06 22:07:34 +02:00
jmp.ae .3
2019-06-05 22:59:32 +02:00
xchg b[ax0], b[ax1]
inc ax0
dec ax1
jmp .2
.3:
ret