Hi, everybody
I'm new to assembly and, as I'm trying to understand memory handling with push and pop, I started to create a little win32 console application that should get the command line arguments count (argc), check if they are more than 2 and show an error message if not so. That simple. The code in C/C++ would be:
void ShowError() {
printf ("Command unrecognized!");
}
int main (int argc. char** argv[]) {
if (argc<2) ShowError();
return 0;
}
Now, in Assembly (with NASM), this is what I have
global Start
extern _printf
extern _ExitProcess@4
section .data
ArgumentsError db 'Not enough arguments %d!', 10, 0
section .text
Start:
; Get argc (which I don't know if really works)
pop ebx
; If argc < 2 then show error
cmp ebx, 2
jl ShowError
; Close application with no error
push 0
call _ExitProcess@4
hlt
ShowError:
sub esp, 4
push ArgumentsError
call _printf
add esp, 4
ret
So, if I compile this file with NASM and link it with GCC into a test.exe win32 binary and execute it (without any argument in the command line), I don't get the error. It's like the cmp instruction's result is always greater than 2. I don't know what am I doing wrong. If I use jg instead of jl I get that error message.
Thanks for your help!