RE: ASM push

new topic     » topic index » view thread      » older message » newer message

Subject: ASM Push




> Is there an order you are suppose to push the vars?

Definitely. Each routine's design includes how many parameters it takes and
where 
they are to be fetched on the stack, ie in which order they must have been
pushed 
prior to call.

> I keep getting errors unless my push calls are in
> a specific order. The only problem is I can't seem
> to figure out what that order is except by guess
> and check. Does anyone know anything about this?

What do you know about the routine you are going to call?
- If it is in Pscal/Delphi, the parameters are pushed lrftmost first;
leftmost refers to the line that declares the routine, like in: function
foo(bar1:integer var bar2: integer)
- If it comes from C, parameters are pushed rightmost first.
- If it comes from an OO language, it may use a specific calling convention,
refer to the .dll/.so doc to find out.

In Intel-based CPUs, call parameters and return addresses are consecutibvely
stacked in some 
segment - the stack segment. Ordering is hence crucial. push will add an
extra dword
on the top of the stack, shifting stack pointer (register ESP) 1 dword down.
pop does the reverse: it retrieves the top dword, stores it where the
argument to pop says
an shifts ESP 1 dord up. You can also acccess the stack randomly - that's
how routines 
get the arguments passed to them.

Oh, and remember that some compilers use calling scheme where arguments are
niot pushed at all,
unless there are too many of them; I think this is called "fastcall".

To sum it up, you must know, or infer from the native language or compiler
used, in which
order params are pushed onto the stack for the routine to get what it
expects to from each relative location on the stack it is aware of.

HTH
CChris

-Damien Black

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu