Macro idea is a piece of program code with independent functions in the source program.
Macro commands: User-defined commands. During programming, the functions used for multiple times are replaced by a macro command.
Compilation includes commands, pseudo commands, and macro commands. The first two are both defined, and the last one is designed by yourself.
The advantage is that it is easy to use, such as:). It is defined for use, but must be defined first and then called.
(This is different from the subroutine)
For example, a macro is defined to multiply two words.
Multiply macro opr1, opr2, result
Push DX
PUSH AX
MoV ax, opr1
Imul opr2
MoV result, ax
Pop ax
Pop DX
Enom
Call this macro,
Multiply CX, VAR, XYZ [BX]
Macro expansion
1 Push DX
1 PUSH AX
1 mov ax, CX
1 imul VaR(VAR cannot set the immediate number)
1 mov XYZ [BX], ax
1 pop ax
1 pop DX
(That is, take it in. You can see it clearly. Note that it must be valid after the exhibition)
For example, calculate the absolute value
Macro definition,
Absol macro labels
Local next
CMP protocol, 0(Compared with 0)
Jge next
Neg Subnet(The sum is the absolute value)
Next:(Prevent multiple accesses to an address)
Endm
Macro call,
.........
Absol VaR
.......
Absol BX
Macro exhibition,
1 CMP var, 0
1 jge ?? 0000
1 neg VaR
1 ?? 0000:
..........
1 cmp bx, 0
1 jge ?? 0001
1 neg BX
1 ?? 0001:
(It is very clear that you have prepared a formula and then brought it in,
Compilation is interesting only when it is learned here :))
& Use
For example, macro definition,
Leap macro cond, lab
J & cond lab
Endm
Macro call
Leap Z, there
.........
Leap NZ, here
Macro exhibition,
1 JZ there
.........
1 jnz here
(I understand it. It means "and". It means nothing to talk about ,)
For example
MSG macro lab, num, XYZ
Lab & num dB 'welcoeme you study with Jinzhou Mr, & xyz'
Endm
Macro call
MSG ary, 1, Wang(There is no need to comment this place. It is called twice :)
......
MSG ary, 2, Zhang
Macro expansion
1 ary1 dB 'welcoeme you study with Jinzhou Mr Wang'
.......
1 ary2 dB 'welcoeme you study with Jinzhou Mr Zhang'
(It's very easy. It's a good game ,)
% Usage
For example,
Macro definition,
MSG macro count, string
MSG & COUNT dB string
Endm
Errmsg macro text
Cntr = cntr + 1
MSG % cntr, text
Endm
Macro call
Entr = 0
....
Errmsg 'syntax error'
.......
Errmsg 'invalid operand'
Macro expansion
1 cntr = cntr + 1
1 MSG % cntr, 'syntax error'
2 msg1 dB 'syntax error'
...........
1 cntr = cntr + 1
1 MSG % cntr, 'invalid operand'
2 msg1 dB 'invalid operand'
(Here we can see, it is a replacement. Generally, we can only see what 2 shows. In order to understand clearly,
Write 1)
Macro Library Creation and calling (generally with Mac suffix)
It's easy to create a macro library. Just upload the number and change it to a program.
Input Macro. MacMacro1 macro
........
Endm
.....Macro2 macro
.........
Endm
.......
(How much to use)
Call,
Add path using include
It is very simple.
Let's briefly describe the differences between macro calls and subprograms:
A subroutine is called during program execution and only occupies a space of its own size.
(The IP address of the subroutine is required. The advantage is that the memory is saved and the efficiency is high,
However, it takes a long time to save the return address and switch to the address, which is suitable for long code,
Frequently called)
Macro call, which is expanded during assembly and is called once.
The following is a macro of the invoke function.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>
; Sample code for <win32asm programming 2nd Edition>
By Luo Yun bin, http://asm.yeah.net
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>
; Reverse the order of the parameter list
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>
Reverseargs macro Arglist: vararg
Local txt, count
TXT textequ <>
Count = 0
For I, <Arglist>
Count = count + 1
TXT textequ @ catstr (I, <!,>, <% TXT>)
Endm
If Count GT 0
TXT substr txt, 1, @ sizestr (% txt)-1
Endif
Exitm txt
Endm
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>
; Create a macro similar to invoke
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>
_ Invoke macro _ proc, argS: vararg
Local count
Count = 0
% For I, <reverseargs (ARGs)>
Count = count + 1
Push I
Endm
Call dword ptr _ proc
Endm
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>