Could somebody tell me a book about macro?
I konw nothing about macro and never used macro to write a asm.
This is the code i do not understand.especially the  'pseudoinstruction' Thanks friends.
_invoke		macro	_Proc,args:VARARG
local count
count = 0
% for i,< reverseArgs( args ) >
count = count + 1
push i
call dword ptr _Proc   

Posted on 2007-05-15 21:15:16 by ekin
Macros (aka 'buildtime procedures') basically fall into two categories : those which perform a calculation (at BuildTime) and return some kind of value, and those which emit one or more OpCodes, which are then processed as if you had actually written them.

Macros are most often used to disguise relatively short and frequently-used blocks of code, which can make your sourcecode shorter and nicer to look at, in other words they can be used to hide from the casual reader what the heck is actually going on.
In that respect, they are a mixed blessing.

I have never seen one decent tutorial on this subject, let alone a book, however Randy Hyde's AoA is probably as good as it gets (chapter 8 from memory).

Like most users, I've learned what I know about (masm) macros by studying the ones I've encountered in other people's sources.

The most fundamental difference between macros and procedures in terms of design is that macros can work with params that contain some Text (rather than some fixed size of arbitrary data, like dword).
Your example macro is doing just that - its parameters are Text based.
The macro you have posted emits a number of opcodes.. specifically, given that '_Proc' is the name of a procedure, and 'args' is 0 or more comma-delimited arguments, your macro emits a PUSH opcode for each and every comma-delimited argument in 'args' (in reverse order of appearance), and then emits 'Call _Proc', where _Proc is replaced with its Text Content.
The result of all this is a 'Standard Call' to an arbitrary procedure.

For example, if we did this:
_invoke MyProc, XX, YY, ZZ

that would cause the following code to be emitted:
push ZZ
push YY
push XX
call MyProc

A macro PSEUDOINSTRUCTION is a macro which emits one or more OpCodes, like we just saw.
Here's a better example... you already know that theres no X86 opcodes that allow you to move a value directly from one memory location to another - you're forced to load into a register, and then store again.

m2m macro Dest, Source
push Source
pop Dest

Now an example usage of that macro:
m2m MyBackupVariable, MyWorkingVariable

That would generate this:
push  MyWorkingVariable
pop  MyBackupVariable

We can use 'm2m' AS IF it was an actual opcode, so our SourceCode can be shorter and less ugly to look at. Since we understand the macro, we know it really generates TWO opcodes for each 'm2m' in our sourcecode, but we could quite easily use this macro WITHOUT understanding how it really works (which I think is bad, but hey, isn't this what C, C++, VB and other HLLs REALLY DO?)

Hope this has helped you in some small way :)
Posted on 2007-05-16 02:36:10 by Homer
I have a "PseudoInstruction.asm" file in my kernel's project directory and I have coded something like this:

; ??????????????????????????????????????????????????
  %IF %3 = _EAX
    MOV    AL , BYTE PTR [%2]
    MOV    BYTE PTR [%1] , AL
  %IF %3 = _EBX
    MOV    BL , BYTE PTR [%2]
    MOV    BYTE PTR [%1] , BL
  %IF %3 = _ECX
    MOV    CL , BYTE PTR [%2]
    MOV    BYTE PTR [%1] , CL
  %IF %3 = _EDX
    MOV    DL , BYTE PTR [%2]
    MOV    BYTE PTR [%1] , DL
; ??????????????????????????????????????????????????

Using the above macro, you can move a byte from a memory location to another. For example, you can do something like this:

  MOV     ESI , OFFSET SourceString
  MOV    EDI , OFFSET DestinationString

And the above code will the AL register to first copy the content of the byte at the memory location to which ESI points, to the memory location inside the EDI register.

Hope it gives you a hint.
Posted on 2007-05-16 19:42:31 by XCHG
Thanks a million!This is really helpful. ;)But could some tell a litter about the syntax about the macro?like the
for	i,< reverseArgs( args ) >
I wish i could write macro by my self.
Posted on 2007-05-16 22:59:32 by ekin