I'm learning Assembly language. What exactly is argument push order? i understand its how arguments are pushed to the stack but what does the left and right part mean? left or right of what? Or is this merely to do with the way the command is semantically written, i.e.:
mov ebp, esp ;esp is moved into ebp, right to left.
Is this correct or could someone enlighten me?
Many thanks!
ST0 must also be empty when not used for returning a value. In the context of the C programming language, function arguments are pushed on the stack in the right-to-left order, i.e. the last argument is pushed first. The caller cleans the stack after the function call returns.
They are pushed right to left so that the leftmost argument is always at the top of the stack in the called function's frame.
Yes, it matters. The arguments must be given in the order the function expects them. C passes arguments by value. It has no way of associating a value with an argument other than by position.
The processor knows no 'function arguments'. Therefore when you want to write f(a,b,c)
, you really need to push the arguments 'somewhere'.
This is convention. I know that on most x86 machines, function arguments are pushed on the stack from right to left, i.e. first c, then b, then a.
push c
push b
push a
call f
Now the called function can use ebx -1
for a, ebx - 2
for b and ebx - 3
for c.
You could as well establish a convention that says: first two arguments are in registers ebx
and ecx
, rest are on the stack. As long as the caller and callee agree, you're fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With