kvisc/ka/str/strcmp.k

53 lines
899 B
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.
;
; int strcmp(const char *str1, const char *str2)
;
; Returns:
; 0 if the contents of both strings are equal
; 1 if the first character that does not match has a greater value in str1 than in str2
; -1 if the first character that does not match has a lower value in str1 than in str2
;
strcmp:
cmp b[ax0], b[ax1]
jmp.nz .1
test b[ax0], b[ax0]
jmp.z .1
inc ax0
inc ax1
jmp strcmp
.1:
mov rax, b[ax0]
sub rax, b[ax1]
sgn rax, rax
ret
;
; int strncmp(const char *str1, const char *str2, int maxn)
;
strncmp:
mov rcx, ax2
.0:
cmp b[ax0], b[ax1]
jmp.nz .1
test b[ax0], b[ax0]
jmp.z .1
inc ax0
inc ax1
loop .0
.1:
mov rax, b[ax0]
sub rax, b[ax1]
sgn rax, rax
ret