The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: JFG on October 06, 2005, 10:56:44 PM

Title: ADDR operator on stack data, and parameter registers
Post by: JFG on October 06, 2005, 10:56:44 PM
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?
Title: Re: ADDR operator on stack data, and parameter registers
Post by: Jeff on October 06, 2005, 11:09:58 PM
as i understand it, ADDR works with stack data by design.  the only problem is that it doesnt preserve the eax register.
Title: Re: ADDR operator on stack data, and parameter registers
Post by: QvasiModo on October 06, 2005, 11:32:53 PM
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

Title: Re: ADDR operator on stack data, and parameter registers
Post by: JFG on October 07, 2005, 05:59:44 AM
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.
Title: Re: ADDR operator on stack data, and parameter registers
Post by: MazeGen on October 07, 2005, 01:07:10 PM
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".
Title: Re: ADDR operator on stack data, and parameter registers
Post by: JFG on October 07, 2005, 11:56:19 PM
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?
Title: Re: ADDR operator on stack data, and parameter registers
Post by: GregL on October 08, 2005, 12:34:18 AM
Here's a PDF version. MASM Programmer's Guide (http://www.visualassembler.com/downloads/MASM61PROGUIDE.pdf)
Title: Re: ADDR operator on stack data, and parameter registers
Post by: MazeGen on October 11, 2005, 12:36:59 PM
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 (http://www.google.com/search?q=MASM+programmer+guide) opens also these unattainable caves :P

Note that there is also Word doc version, which is more useable for me.
Title: Re: ADDR operator on stack data, and parameter registers
Post by: JFG on October 17, 2005, 03:30:34 AM
Thanks!  This will help a lot.