You are xor'ing cl after setting carry flag. This is a bad idea.
assembly x86: simple string comparison routine
-
16-06-2023 - |
Pregunta
What's the problem with this routine? it won't work for the given values below. I'm using this in a shell for a simple kernel but I have no idea why it doesn't work.
mov si, buffer ; buffer value from user input: 'help'
mov di, shell_command_help ; shell_command_help db 'help',0
call os_compare_string
; ----------------------------------------------------------
; Routine: Compare equality of two strings
; Waits for a complete string of user input and puts it in buffer.
; Sensitive for backspace and Enter buttons
; Input 1. String1 in SI 2. String2 in DI
; Output 1. result in carry flag
; ----------------------------------------------------------
os_compare_string:
.compare_next_character: ; a loop that goes character by character
mov al, [si] ; focus on next byte in si
mov bl, [di] ; focus on next byte in di
cmp al, bl
jne .conclude_not_equal ; if not equal, conclude and exit
; at this point we know the two bytes are equal
cmp bl, 0 ; did we just compare two zeros?
je .conclude_equal ; if yes, we've reached the end of the strings. They are equal.
; increment counters for next loop
inc di
inc si
jmp .compare_next_character
.conclude_equal:
stc ; sets the carry flag (meaning that they ARE equal)
jmp .done
.conclude_not_equal:
clc ; clears the carry flag (meaning that they ARE NOT equal)
jmp .done
.done:
xor cl, cl
ret
Solución
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow