I'm beginning with assembly (x86, linux), just for fun. This is my very first little program, which just checks if I passed one argument through command line and if not it prints a message, and it exits after that:
section .text
global _start
_start:
pop ebx ;argc
dec ebx
test ebx,1
jne print_string
exit:
mov ebx,0
mov eax,0
int 0x80
print_string:
mov edx,len
mov ecx,msg
mov ebx,1
mov eax,4
int 0x80
call exit
section .data
msg db "Ok, no arg was passed",0xa
len equ $ - msg
I'm having two problems with the code above:
jne
is not taken. I checked with gdb thatebx
is equal to 0x00 afterdec
, but EFLAGS are not changed by thetest
instruction.- exit syscall does not exit! So instead of exiting I just got my message printed in an infinite loop, as print_string is calling exit and after exit there goes print_string over and over again.
What's happening here? Also any other recommendations about the code will be welcome. Thanks.