assembly strcmp function acting weirdly
Posted: Fri Sep 18, 2015 10:41 am
Ok. I have a strcmp function that I wrote in assembly that looklikes this:
And then somewhere else I have these 4 declared:
And at the final step, in the main loop, (which has an input further down so it doesn't run in an endless loop), I have this:
So, what I'm expecting to happen is that when I do strcmp, the carry flag will be set. which will cause .skip not to be called right after. so what I want to happen is that is print msg_cmp_success then msg_cmp_end.
But for some reason, the carry flag doesn't get set, even though they are both equal, which makes it just show the msg_cmp_end
So what is the problem here? why doesn't the carry flag get sent, marking them as equal, and how do I fix it?
Code: Select all
strcmp:
.loop:
mov al, [si]
mov bl, [di]
cmp al, bl
jne .notequal
cmp al, 0
je .done
inc si
inc di
jmp .loop
.notequal:
clc
ret
.done:
stc
ret
Code: Select all
msg_one db "test", 0
msg_two db "test", 0
msg_cmp_success db "success", 0
msg_cmp_end db "end", 0
Code: Select all
mov si, msg_one
mov di, msg_two
call strcmp
jnc .skip
mov si, msg_cmp_success
call print_string
.skip:
mov si, msg_cmp_end
call print_string
But for some reason, the carry flag doesn't get set, even though they are both equal, which makes it just show the msg_cmp_end
So what is the problem here? why doesn't the carry flag get sent, marking them as equal, and how do I fix it?