Code:
%define x 0x03
x equ 0x03
What's the difference between them?
%define
is a far more powerful way of doing macros, akin to the C pre-processor. In your simplistic case, there is not a lot of difference, using x
in the source code will result in the constant 3
being substituted. There's a subtle difference in that equ
statements are evaluated once, when they are first read and %define
macros are evaluated whenever they are encountered in the source.
You can see the difference there between the two statement snippets:
addr equ $
%define addr $
In that case, addr
, when encountered in the code, will have different values. In the first case, $
will be the location of the assembly position at the place where the equ
is. In other words, where it's defined.
In the second case, it evaluates to the assembly location at the place where addr
is used.
Where %define
shines is with something like:
%define thricexplusy(x,y) (3 * x + y)
or:
%define ctrl(c) (c & 0x1F)
: :
mov al, ctrl('z')
(or even considerably more complex things) which allow you to pass parameters to your macro, something not possible with a simple equ
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With