NASM Forum > Example Code

Command Line Arguments using NASM and GCC

<< < (2/2)

stressful:

--- Quote from: rajex on March 07, 2018, 01:23:07 PM ---Can you help me understand how the OS calls the binary with the command-line arguments on the stack to the _start subroutine, I can't quite figure out my around esp and ebp.

--- End quote ---

rajex

as told by Frank, this example is configured for GCC. _start is an "ld" thing and has a slightly different method of placing / taking the command line arguments.

Anyway, if memory serves, "ld" places argument count on top of stack and the rest are pointers to the subsequent arguments. One good thing about "ld" is that it separates the arguments with 0 for you so you can have null-terminated strings for each. Should be something like this;

--- Code: --- section .text
_start:
mov ebp,esp

mov eax,[ebp] ;arg count
mov ebx,[ebp+4] ;prog's name string address
mov ecx,[ebp+8] ;arg1 string address
mov edx,[ebp+12] ;arg2 string address
--- End code ---

Hope this helps.

Navigation

[0] Message Index

[*] Previous page

Go to full version