I am very new to assembly code and need to know how to pass command line arguments (argc, argv, env) in as function arguments. At line 2 (#RIGHT HERE) is where I do not know the implementation and I need to pass the three arguments into my main. Can anyone please help?
I am compiling it by running: gcc -m32 t.c s.s. The code below is s.s and mymain is in t.c
main:
#RIGHT HERE
call mymain
ret
You'd have to understand the 32bit linux ABI (application binary interface) which describes the calling conventions for passing argument and stack usage. I'm not going to list all the details out here, but they're easily accessible on the web.
A quick summary : 32bit linux will need the arguments stored on the stack before your call. You'll need sufficient stack space to store the arguments, or "push" them on, which will automatically decrement the stack pointer. This space needs to be cleaned up after your call returns.
If you don't want to spend the time researching the ABI, a simple alternative is to write a C program that calls a function passing in all your arguments, then simply compile it and look at the assembly to see how it was done, and copy.