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/crt/str/strrev.k

71 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:
2019-07-17 22:25:50 +02:00
cmp b[ax1], zero
mov.z b[ax0], zero
2019-06-06 22:07:34 +02:00
ret.z
2019-05-30 18:31:50 +02:00
2019-05-30 18:36:06 +02:00
; save str's location
2019-07-22 13:18:13 +02:00
mov rsi, 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-06-16 21:17:56 +02:00
mov rcx, STRLEN_MAX
2019-07-17 22:25:50 +02:00
scasb.rep.nz ax1, zero
2019-08-03 17:41:44 +02:00
dec ax1, 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-08-03 17:41:44 +02:00
mov b[ax0], b[ax1]
2019-05-30 18:31:50 +02:00
2019-07-22 13:18:13 +02:00
cmp ax1, rsi
2019-07-17 22:25:50 +02:00
mov.z b[ax0+1], zero
2019-06-06 22:07:34 +02:00
ret.z
2019-05-30 18:31:50 +02:00
2019-08-03 17:41:44 +02:00
inc ax0, 1
dec ax1, 1
2019-05-30 18:31:50 +02:00
jmp .2
2019-06-05 22:59:32 +02:00
;
; void strrev2(char *str)
;
; Inverses str
;
strrev2:
2019-07-17 22:25:50 +02:00
cmp b[ax0], zero
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
2019-06-16 21:17:56 +02:00
mov rcx, STRLEN_MAX
2019-07-17 22:25:50 +02:00
scasb.rep.nz ax1, zero
2019-08-03 17:41:44 +02:00
dec ax1, 1
2019-06-05 22:59:32 +02:00
; increase ax0 while decreasing ax1, performing exchanges
.2:
2019-07-02 20:13:05 +02:00
b.ae ax0, ax1, .3
2019-06-05 22:59:32 +02:00
2019-08-03 17:41:44 +02:00
xchg b[ax0], b[ax1]
2019-06-05 22:59:32 +02:00
2019-08-03 17:41:44 +02:00
inc ax0, 1
dec ax1, 1
2019-06-05 22:59:32 +02:00
jmp .2
.3:
ret