The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: MusicalMike on September 28, 2005, 12:21:17 AM

Title: Implimentation Question
Post by: MusicalMike on September 28, 2005, 12:21:17 AM
As a student programmer, I have a rule that I hold myself to that basicly says this.

For all the WYSISYG editors, helper macros, code generators, etc that are out here, I should not use them unless I know how to produce the same code or functionality by myself and understand how it works.

So that being said, I started hunting for the declairation code for the invoke macro, I had no luck. I tried looking at the output code generated by the different passes of the assembler to atleast see what code the invoke macro would equate to durring "assemble time" (if thats what its called), also had no luck, for some reason, no matter what pass I was looking at, I still only saw the invoke macro (accept for the final pass, where there was so much other code from the include files amoung other things that I couldn't find it). So basicly I am back where I started. Could someone tell me where I could find information on how exactly the invoke macro was implimented?

Insidently, I am aware that it involves the push and call combo however, I am more interestedin how the invoke macro handles local variables, particularly, when the function you are calling requires the affective address of a local (which is determined at runtime so I am guessing requires the lea instruction although I try to use only globals if I can help it so, Ill just admit it, I have no idea how to push the address of a local variable onto the stack).
Title: Re: Implimentation Question
Post by: Jimg on September 28, 2005, 01:41:42 AM
Hi Mike-

Invoke isn't a macro, it's an intrinsic Masm command.
Title: Re: Implimentation Question
Post by: Ratch on September 28, 2005, 03:25:11 AM
MusicalMike,
     You might want to read this thread. Ratch

http://www.masmforum.com/simple/index.php?topic=239.0
Title: Re: Implimentation Question
Post by: MusicalMike on September 28, 2005, 03:42:35 AM
Interesting, The masm documentation always refered to it as the "invoke macro" and well, I just thought, in this case I guess I thought wrong. That would definitely explain why I can't find a macro definition on it. However the question still remains, what does the code that the invoke "keyword" equates to durring the final pass of the assembler in regards to dealing with local variables (or variables dynamicly alocated on the heap for that matter)?
Title: Re: Implimentation Question
Post by: hutch-- on September 28, 2005, 03:45:07 AM
Mike,

INVOKE and PROTO are part of the same built in capacity in MASM for type checking so you will not find a macro to do that. The best way to see what an invoke statement does is assembler the file, disassemble it with DumpPE and then have a look at what it has done. To make finding the location in the code a lot easier, try placing a few nops before and after what you want to look at.

With LOCALS invoke usually does an LEA EAX, LOCALVALthen PUSH EAX. It will warn you if you have used EAX earlier and are overwritng it. With a normql STDCALL function which most are, you push the arguments in reverse order then call the function.

At its simplest, something like this.


invoke MessageBox,hWnd,ADDR txt,ADDR titletxt,MB_OK

do it as push call and it looks like this.

push MB_OK
lea eax, titletxt
push eax
lea eax, txt
push eax
push hWnd
call MessageBox
Title: Re: Implimentation Question
Post by: MusicalMike on September 28, 2005, 07:14:59 PM
Thanks, thats exactly the information I needed.
Title: Re: Implimentation Question
Post by: raymond on September 29, 2005, 03:04:45 AM
MusicalMike,

Understand that Hutch's latest expanded example assumes that titletxt and txt are LOCAL variables. If they were GLOBAL variables, their address would be known at compile time and would be pushed directly without the need to use EAX.

Raymond
Title: Re: Implimentation Question
Post by: QvasiModo on September 29, 2005, 03:30:59 PM
Quote from: MusicalMike on September 28, 2005, 03:42:35 AM
The masm documentation always refered to it as the "invoke macro"

My 0,2 cents: the masm documentation refers to invoke as a "built in macro", hence the confusion.
Title: Re: Implimentation Question
Post by: Mirno on September 29, 2005, 04:26:47 PM
If you use MASMs ability to generate a list file, you can see macros expanded in there.

Use "ml /c /Fllist.txt /Sa /Sn my_asm.asm" to generate a full list file (be aware it expands the include directives too, so the file is huge), down the bottom will be the full code you've generated with invokes expanded.

Mirno
Title: Re: Implimentation Question
Post by: GregL on October 02, 2005, 12:39:33 AM
You can use .NOLIST and .LIST around the includes to exclude them from the listing.


Title: Re: Implimentation Question
Post by: hutch-- on October 02, 2005, 01:05:44 AM
The safest way I have found with getting everything expanded up when you are writing macros is to use the /EP option and redirect the output to a file. I am probably not in practice well enough with the .LIST options but I usually miss something when using them where te /EP option dumps the lot.