Octocontrabass wrote:
I think your strcmp function is working correctly, but it's not doing what you want because you have made a mistake somewhere else.
Here is the first, working code, that calls the strcmp (just copy pasting):
Code: Select all
mov si, buffer
cmp byte [si], 0
je .k_main_loop
mov si, buffer
mov di, cmd_help
call strcmp
jc .help
and this is the non-working code:
Code: Select all
mov si, buffer
cmp byte [si], 0
je .done
mov si, buffer
mov di, os_cmd_help
call strcmp
jc .os_crun_help
FYI, I tried making a "strcmp_v" function where the v means Verbose, like logging everything to the user. Here's that code:
Code: Select all
strcmp_v:
pusha
mov si, ._v_clear_str
call screen_print_string
popa
.loop:
mov al, [si]
mov bl, [di]
cmp al, bl
jne .notequal
call ._v_cmp_s
call ._v_cmp_d
cmp al, 0
je .done
pusha
mov si, ._v_clear_str
call screen_print_string
popa
inc di
inc si
jmp .loop
.notequal:
pusha
mov si, ._v_ne
call screen_print_string
popa
call ._v_ncmp_s
call ._v_ncmp_d
pusha
mov si, ._v_clear_str
call screen_print_string
popa
pusha
mov [out_byte], al
call screen_write_byte
mov si, os_nl
call screen_write_string
mov [out_byte], bl
call screen_write_byte
mov si, os_nl
call screen_write_string
popa
pusha
mov si, ._v_clear_str
call screen_print_string
popa
clc
ret
.done:
stc
ret
._v_cmp_s:
mov [._v_char], al
pusha
mov ah, 0x0E
mov al, byte [._v_char]
mov bh, 0x00
mov bl, 0x0F
int 0x10
mov si, os_nl
call screen_write_string
popa
ret
._v_cmp_d:
mov [._v_char], bl
pusha
mov ah, 0x0E
mov al, byte [._v_char]
mov bh, 0x00
mov bl, 0x0F
int 0x10
mov si, os_nl
call screen_write_string
popa
ret
._v_ncmp_s:
mov [._v_char], al
pusha
mov ah, 0x0E
mov al, byte [._v_char]
mov bh, 0x00
mov bl, 0x0F
int 0x10
mov si, os_nl
call screen_write_string
popa
ret
._v_ncmp_d:
mov [._v_char], bl
pusha
mov ah, 0x0E
mov al, byte [._v_char]
mov bh, 0x00
mov bl, 0x0F
int 0x10
mov si, os_nl
call screen_write_string
popa
ret
._v_char db 0, 0
._v_clear_str db "------------", 0
._v_ne db "--NotEqual--", 0
The thing here, is that everytime you see pusha and popa, between those are something that displays a log statement. so I backup the registers with pusha, change them to display a string/character and then a new line, then I do popa and continue with the normal strcmp. Note that this is a normal strcmp with this pusha-log-popa statements pasted every now and then.
Some other notes is that screen_write_string is writing a string to the screen and screen_print_string is the same but adds \r\n to the end.
The good thing with the strcmp_v, is that it actually says they are equal, even though the original one (which is the same, just without the push-log-pop stuff) says they are not.
So any idea what it could be?