News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

ADDR operator on stack data, and parameter registers

Started by JFG, October 06, 2005, 10:56:44 PM

Previous topic - Next topic

JFG

Does the ADDR operator work okay when used with stack data, or do we have to lea stack addresses when passing them as parameters?  Also, is it okay to pass register values as procedure parameters directly, as in

  invoke  ProcName, eax, ebx

or is there just some issue sometimes that can make ML complain about register conflicts when we pass them as parameters to invoke?

Jeff

as i understand it, ADDR works with stack data by design.  the only problem is that it doesnt preserve the eax register.

QvasiModo

ADDR works just like OFFSET for global variables (in the .data or .data? section) as long as they were already defined. For local variables (in the stack) it generates a LEA EAX, [EBP + something] instruction automatically. For that reason sometimes MASM complains when you pass EAX as a parameter to INVOKE: it has to destroy the previous value of EAX to calculate the address in runtime. An example:


invoke ProcName, addr Var1, addr Var2


...generates...


lea eax, [Var2]
push eax
lea eax, [Var1]
push eax
call ProcName


...so if you try to pass EAX as a parameter...


invoke ProcName, eax, addr Var2


...it would try to do (but won't let you)...


lea eax, [Var2]
push eax
push eax         ; whoops! our first parameter was destroyed by LEA
call ProcName


JFG

Thanks for that bit of info!  That's really good to know.  This is definitely going to save me from some frustration.  We should have details like this in the MASM32 Help program - or better yet, at least in a formal tutorial included in the masm32 package.  These are the sorts of obscure but critical details that really get people.

MazeGen

I am sure you can find it in the masm programmer's guide.

BTW, when you try to compile it, you will get "error A2133: register value overwritten by INVOKE".

JFG

Where's this MASM programmer's guide that people keep mentioning?  Is it on MSDN, or is it some printed thing kept in a cave at the top of some remote mountain in the middle of the Himalayas?

GregL


MazeGen

Quote from: JFG on October 07, 2005, 11:56:19 PM
...is it some printed thing kept in a cave at the top of some remote mountain in the middle of the Himalayas?

Google opens also these unattainable caves :P

Note that there is also Word doc version, which is more useable for me.