Fix strcmp()
This commit is contained in:
37
string.asm
37
string.asm
@ -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
|
||||
|
Reference in New Issue
Block a user