How can I use a local variable in an API call? Since a lot of the parameters need offset, and you can't do that with locals...Do I lea into a register and then pass the register?

lea eax, my_variable
Invoke FakeAPI, eax
Posted on 2002-08-27 02:51:22 by ddh
yes this is exactly the way. The first couple of years you program (not only in assembly) you will
probably mix up pointers, pointers to pointers, offsets and so on. But afterwards things get better ... :grin:
Posted on 2002-08-27 03:57:15 by beaster
I actually understand pointers in assembly better than in C++ and what not. :) Figured it'd be harder..ah well. :) Thanks, was just wondering.
Posted on 2002-08-27 04:19:37 by ddh
ddh: if you use masm then the
addr directive(only used with invoke) on a local variable will expand to:

lea eax,local_var
push eax

so the following bit of code...
Invoke FakeAPI, addr local1,addr local2 expands to...

lea eax,local2
push eax
lea eax,local1
push eax
call FakeAPI

As you can see the addr directive overwites eax, so if you did something like:
Invoke FakeAPI,eax , addr local1,addr local2 ...which expands to
lea eax,local2
push eax
lea eax,local1
push eax
push eax ;<--eax has been changed
call FakeAPI
you'll get the compile time error :register overwritten by invoke

however if you do:
Invoke FakeAPI, addr local1,addr local2,eax
this is OK
Posted on 2002-08-27 05:48:47 by MArtial_Code
Hm thanks for the information. :)
Posted on 2002-08-27 05:51:17 by ddh

LEA is the right choice for a stack variable, MASM uses different notation for variables in the DATA or DATA? sections and a variable that is created dynamically on the stack, thats the reason for the difference.

OFFSET refers to a variable that is in the memory image of the loaded file where a stack variable is only set while the proc that contains it is running so Load Effective Address (LEA) actually loads the address of the variable on the stack into the register of your choice.

Posted on 2002-08-27 07:23:47 by hutch--