=、EQU、TEXTEQU 功能差不多, 它們定義的符號都將在編譯前輩替換成它們指定的常量值.
相比之下 EQU 更好用些.
= 舉例
; Test13_1.asm
.386
.model flat, stdcall
include Windows.inc
include kernel32.inc
include masm32.inc
include debug.inc
includelib kernel32.lib
includelib masm32.lib
includelib debug.lib
.data
n = 1 ; = 偽指令只能定義整數或整數表達式
n = n + 1 ; 可重復定義
.code
main proc
PrintDec n ;2
ret
main endp
end main
EQU 例一
; Test13_2.asm
.386
.model flat, stdcall
include Windows.inc
include kernel32.inc
include masm32.inc
include debug.inc
includelib kernel32.lib
includelib masm32.lib
includelib debug.lib
.data
num1 equ 2 ; equ 可以定義整數和整數表達式
num2 equ 3 ; 它不能像 = 一樣重復定義
num3 equ num1+num2 ; (我嘗試了重復定義, 竟然有時也可以, 只是偶爾)
txt equ <'Asm'> ; 可用 equ 定義字符串, 應使用 <>
szTxt db txt, 0 ; 使用 equ 定義的常量
.code
main proc
PrintDec num3 ;5
PrintString szTxt ;Asm
ret
main endp
end main
EQU 例二
; Test13_3.asm
.386
.model flat, stdcall
include Windows.inc
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
; 用 equ 給函數重命名
Msg equ MessageBox
Exit equ <ExitProcess>
; 甚至代替整個表達式
ShowMsg equ <invoke MessageBox, NULL, addr szMsg, addr szCaption, MB_OK>
.data
szMsg db 'Hello World!', 0
szCaption db 'Hi', 0
.code
main proc
invoke Msg, NULL, addr szMsg, addr szCaption, MB_OK
ShowMsg
invoke Exit, NULL
main endp
end main
用 TEXTEQU 重做上一個例子, 完全可行:
; Test13_4.asm
.386
.model flat, stdcall
include Windows.inc
include kernel32.inc
includelib kernel32.lib
include user32.inc
includelib user32.lib
Msg textequ MessageBox
Exit textequ <ExitProcess>
ShowMsg textequ <invoke MessageBox, NULL, addr szMsg, addr szCaption, MB_OK>
.data
szMsg db 'Hello World!', 0
szCaption db 'Hi', 0
.code
main proc
invoke Msg, NULL, addr szMsg, addr szCaption, MB_OK
ShowMsg
invoke Exit, NULL
main endp
end main
用 TEXTEQU 重做 EQU 的第一個例子(Test13_2.asm), 有區別:
; Test13_5.asm
.386
.model flat, stdcall
include Windows.inc
include kernel32.inc
include masm32.inc
include debug.inc
includelib kernel32.lib
includelib masm32.lib
includelib debug.lib
.data
num1 equ 2 ; 這裡的 equ 換做 textequ 不行
num2 textequ <3> ; 如果用 textequ 定義整數或表達式也要放在 <> 中
num3 textequ <num1+num2> ; 這曾是 num3 equ num1+num2
txt textequ <'Asm'> ;
txt textequ <'Delphi'> ; textequ 可重復定義
szTxt db txt, 0
.code
main proc
PrintDec num3 ;5
PrintString szTxt ;Delphi
ret
main endp
end main