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-11 18:34:21 +02:00
|
|
|
mov r10, 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-07-18 22:49:31 +02:00
|
|
|
sub ax1, 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-07-04 20:33:49 +02:00
|
|
|
mov rax, b[ax1]
|
|
|
|
mov b[ax0], rax
|
2019-05-30 18:31:50 +02:00
|
|
|
|
2019-07-11 18:34:21 +02:00
|
|
|
cmp ax1, r10
|
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-07-18 22:49:31 +02:00
|
|
|
add ax0, ax0, 1
|
|
|
|
sub ax1, 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-07-18 22:49:31 +02:00
|
|
|
sub ax1, 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-07-04 20:33:49 +02:00
|
|
|
mov rax, b[ax1]
|
|
|
|
xchg rax, b[ax0]
|
|
|
|
mov b[ax1], rax
|
2019-06-05 22:59:32 +02:00
|
|
|
|
2019-07-18 22:49:31 +02:00
|
|
|
add ax0, ax0, 1
|
|
|
|
sub ax1, ax1, 1
|
2019-06-05 22:59:32 +02:00
|
|
|
jmp .2
|
|
|
|
|
|
|
|
.3:
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|