Mail Archives: djgpp/1998/02/06/02:24:54
At 01:00 2/5/1998 GMT, Rylan wrote:
[snipped]
>I read that C stores parameters to a function on the stack in reverse
>order. Should I then use an index value of 8 + ??? for the first parameter
>to the function, and just 8 for the second parameter? What is the number to
>use where ??? is to access second, third and n parameters?
It pushes the rightmost (last) arg first, and the leftmost (first) arg last.
This means the first arg ends up being the closest to the top of the stack.
A diagram may help here. This is the stack.
[Last arg]
....
[First arg]
[Return address]
[Saved EBP] ______ EBP points here.
So, assuming all your args are longword size (int or pointer), arg X will be
at address:
[ebp + 8 + 4*(X-1)]
It gets more difficult if you want to pass `long long's or structs. Advice:
Try not to. :) You have to compute where they are by when they were pushed
and how large they are.
>
>The grand question then: how to pass multiple parameters between Nasm and
>C, using the stack?
I hope this has answered your question. If not, let me know.
>
>Please reply by mail if possible.
>
>Any replies appreciated! :)
>--
>Spawned By Rylan
>Is truth beauty or beauty truth?
>
>
Nate Eldredge
eldredge AT ap DOT net
- Raw text -