Fix strcmp()

This commit is contained in:
2025-06-25 08:35:25 +02:00
parent 6df67b18f4
commit 9d265e3db6
2 changed files with 47 additions and 25 deletions

View File

@ -96,32 +96,33 @@ strcat:
leave
ret
;----- strcmp(char* str1, char* str2) -----;
; return value: 0 if both strings are the same, otherwise index in array str1 where strings are to become different
; return value: 0 if both strings are the same, otherwise index in array str1 where strings mismatch
; returns -1 if str2 is longer than str1 and no difference was found before that happens
; TODO: FIX length 13 for TEST strcmp(strBuff1, str1) (see tests.asm, strcmp test 1)
strcmp:
push rbp
mov rbp, rsp
call strlen
mov rcx, rax
mov rax, -1
xor r10, r10
.compareLoop:
inc rax
cmp byte [rdi+rax], 0x0
je .eosFound
mov r10b, byte [rsi+rax]
cmp byte [rdi+rax], r10b
je .compareLoop
jmp .quit
cmp byte [rdi], 0x0
je .0f
mov r11b, byte [rsi]
cmp byte [rdi], r11b
jne .mismatch
inc rdi
inc rsi
inc r10
jmp .compareLoop
.0f:
mov rax, -1
cmp byte [rsi], 0x0
jne .quit
xor rax, rax
jmp .quit
.eosFound:
mov r10, rax
mov rdi, rsi
call strlen
cmp rax, r10
jle .quit
mov rax, -1
.mismatch:
mov rax, r10
.quit:
leave