I'm writing a simple for loop using the FASM assembler. But when I run it, it runs as an infinite loop.
What is the issue?
format ELF64 executable 3
segment readable executable
entry main
main:
mov ax, 8
jmp .loop
.loop:
cmp ax, 0
je .exit
mov edx,11 ;message length
mov ecx,msg ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4
sub ax, 1
jmp .loop
.exit:
mov eax, 1
int 0x80
segment readable writable
msg db "Hello World", 10, 0
at the bottom of the loop you have
so, set eax to 4, then subtract 1 from ax (which is the lower 16 bits of eax), which means ax (and eax) are both now 3. The
cmp ax, 0is always going to be not equal (for theje) after that.Maybe you didn't realize that ax is just the lower half of eax?