I really can't understand why my code doesn't work correctly:
section .data
ok: db "Count of args isn't 1" , 10, 13, 0
err: db "Count of args is 1" , 10, 13, 0
section .text
global _start
_start:
mov rax, [rsp]
cmp rax, 2 ;if ARGC = 1
jne ..@7.ifnot
mov rcx, ok
mov rax, 1
mov rdi, 1
mov rdx, 1
..@10.while: ;print 'Count of args is 1\r\n' into console
cmp [rcx], dword 0
je ..@10.endwhile ;This line
mov rsi, rcx
push rcx
syscall
pop rcx
inc rcx
jmp ..@10.while
..@10.endwhile:
jmp ..@7.ifend
..@7.ifnot: ;if ARGC !== 1
mov rcx, err
mov rax, 1
mov rdi, 1
mov rdx, 1
..@15.while: ;print 'Count of args isn't 1\r\n'
cmp [rcx], dword 0
je ..@15.endwhile
mov rsi, rcx
push rcx
syscall
pop rcx
inc rcx
jmp ..@15.while
..@15.endwhile:
..@7.ifend: ;and exit
mov rax, 60
mov rdi, 0
syscall
When I run `./test` it output "Count of args isn't 1" (expected behavior). But if I run `./test abcd` it print
Count of args is 1
Count of args isn't 1
When the next byte at the address RCX is 0 and program reaches "je ..@15.endwhile" line, it simply does not jump to "..@15.endwhile."
Why?