News:

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

Implimentation Question

Started by MusicalMike, September 28, 2005, 12:21:17 AM

Previous topic - Next topic

MusicalMike

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).

Jimg

Hi Mike-

Invoke isn't a macro, it's an intrinsic Masm command.

Ratch


MusicalMike

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)?

hutch--

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
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

MusicalMike

Thanks, thats exactly the information I needed.

raymond

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
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

QvasiModo

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.

Mirno

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

GregL

You can use .NOLIST and .LIST around the includes to exclude them from the listing.



hutch--

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.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php