Any good NASM / Intel Assembly programmers? If so, I have a question for you!
Every tutorial I can find on the internet shows using βprintfβ to print the actual ARGC value on the screen (fd: / dev / stdout). You cannot just print it with sys_write (), for example:
SEGMENT .data ; nothing here
SEGMENT .text ; sauce
global _start
_start:
pop ECX ; get ARGC value
mov EAX, 4 ; sys_write()
mov EBX, 1 ; /dev/stdout
mov EDX, 1 ; a single byte
int 0x80
mov EAX, 1 ; sys_exit()
mov EBX, 0 ; return 0
int 0x80
SEGMENT .bss ; nothing here
When I run this, I get no output. I tried to copy the ESP to EBP and tried to use the [EBP + 4] byte, (I was told that the brackets would unlink the memory address).
I can confirm that the value compared to the constant works. For example, this code works:
pop ebp ; put the first argument on the stack
mov ebp, esp ; make a copy
cmp byte[ebp+4],0x5 ; does it equal 5?
je _good ; goto _good, &good, good()
jne _bad ; goto _bad, &bad, bad()
When we pop the stack, we technically need to get the full number of arguments, no? Oh, by the way, I am compiling with:
nasm -f elf test.asm -o test.o
ld -o test test.o
, . , .