Alex Rivera | Logout

What is argument push order

Asked 2012-02-04T14:31:40.213
14

I'm learning Assembly language. What exactly is argument push order? I understand it's 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?

Edit
Report

1 Answer

19

The processor doesn't know 'function arguments'. Therefore when you want to write f(a,b,c), you really need to push the arguments 'somewhere'.

How and where to push them is mere 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

Pushing to the stack would, on x86, decrease the stack 'top' with a word. Three words have been pushed, and the return address, so the called function can use top + 1*W for a, top + 2*W for b and top + 3*W 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.

answered 2012-02-04T14:37:26.647

Your Answer