I've been bashing my head against the wall for over an hour and I can't understand why the below doesn't work.
If I change b: db 1 to b: db 0 then it should print 10, otherwise it should print 0. Instead, the program always prints 10.
I've been writing a project that writes assembly and this is one of the unit test that fails and I just don't get it. It has to be something simple.
extern printf, exit
section .bss
section .data
b: db 1
x: dd 5
y: dd 5
z: dd 0
int_pattern: db "%i", 10, 0
global main
section .text
main:
mov eax, dword [b]
cmp eax, dword 0
je condition_end4
; add x and y
; store into z
mov eax, dword [rel x]
add eax, dword [rel y]
mov [rel z], eax
condition_end4:
; rsi = &z
; rdi = &int_pattern
mov rsi, qword [z]
mov rdi, int_pattern
; not using vector registers
xor rax, rax
; printf(int_pattern, z);
call printf
I'm using Debian Linux with NASM. Assembling/linking with
nasm -f elf64 -o test.o test.asm
gcc test.o -o test.bin
Even when b is 0, GDB shows that the cmp unsets ZF so I'm at a loss here.
Thanks!