I am taking a class in x86 assembly language and it's starting to move rather fast. There is one thing that the book keeps doing without mentioning how it works, and that is using the equ and = operators when defining data.
So it seems like equ is used to define constants, but is = the same thing? If I had some code:
.data
count = 100 ; Is this a constant? Of what data type is this?
array WORD count DUP(?)
x_param EQU [EBP + 8] ; Is this a constant?
I am asking because until now we have defined data by declaring it's type, but how does it work when there is no type declared (like count = 100)
I've been googling and searching forums about these operators for the past few days (Spring break), and I cannot come up with anything, so I figure I should ask myself.
EDIT I am using the x86 MASM assembler
Equ Sets the number in stone. = Sets the number until you change it later on. Beware !!! The definition of "later on" can confuse the living daylights out of you; particularly with multiple source files.
EQU is more general in that it allows numeric constants as well as text constants. EQU also explicitly states that a text value can be changed after declaration.
* EQU - The equate directive is used to substitute values for symbols or labels. The format is 'label: EQU value', so whenever the assembler encounters 'label', it replaces this with 'value'.
The EQU instruction assigns absolute or relocatable values to symbols. Use it to: Assign single absolute values to symbols. Assign the values of previously defined symbols or expressions to new symbols, thus letting you use different mnemonics for different purposes.
First, the immediate answer to your question...
Equ
Sets the number in stone.
=
Sets the number until you change it later on.
Beware !!! The definition of "later on" can confuse the living daylights out of you; particularly with multiple source files.
Here is a useful trick that you can use with these two directives to define a bunch of numbers when...
You don't know (when you start out) exactly how many of these you'll want
The_Counter = 0
The_Counter = The_Counter + 1
Fred = The_Counter
The_Counter = The_Counter + 1
Barney = The_Counter
The_Counter = The_Counter + 1
Dino = The_Counter
The_Counter = The_Counter + 1
Arnold = The_Counter
The_Counter = The_Counter + 1
Mr_Slate = The_Counter
The_Counter = The_Counter + 1
Now, as you can see, Fred, Barney, Dino, Arnold, Mr_Slate
could all change their values with this scheme, and that might be a bad thing; so, if you want to make sure that Fred
et.al. don't get changed by somebody else (or yourself, in error) in another part of your source files, then you can combine the =
and the Equ
in the above scheme like this...
The_Counter = 0
The_Counter = The_Counter + 1
Fred Equ The_Counter
The_Counter = The_Counter + 1
Barney Equ The_Counter
The_Counter = The_Counter + 1
Dino Equ The_Counter
The_Counter = The_Counter + 1
Arnold Equ The_Counter
The_Counter = The_Counter + 1
Mr_Slate Equ The_Counter
The_Counter = The_Counter + 1
In this case, they'll still all be different from each other, but their actual values won't be candidates for change.
While this example uses Flintstone's characters for the name, it can easily be changed to something more useful, like...
...and about 47 other good reasons that I can't think up right now.
Oh, just a suggestion; if you want to use this sort of scheme, I find it highly beneficial to place these Equ
and =
directives, etc. into their own include file; generally named SomeFile.Equ
or whatever. I have personally found that by segregating these sorts of assembler directives and such stuff from the actual machine language instructions, you'll find that your code is far more legible, as well as way more maintainable; big time way more. (Just my suggestion.)
Good question, and one that gave me weeks of bewilderment myself.
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