I just started learning assembler language. I came across the concept of EQU. At first it made perfect sense, until I got to DC.B. What is the difference between DC.B and EQU? Can't you just use EQU for every constant?
I'm not familiar with your specific assembler syntax, so this answer is an educated guess.
The EQU directive is used to tell the assembler that you wish to have a named symbolic constant (often computed from other assembler values including other EQU definitions) that you can refer to in other places in the assembly source text. You must always write
symbolname EQU constantexpression
This allows you to write symbolname instead of the constantexpression in other places in your source text. But this name by itself has no direct effect on the final assembled program binary data.
"DC.B" (I assume 'define constant (byte)' is used to tell the assembler that you with the final assembled program to have a byte of data embedded in it at the relative position in the source file". You write
optionalname DC.B constantexpression
to have the computed value of the constant expression placed into a data byte in the assembled program binary data.
So, you might write
AnEvenNumber EQU 2
MyEvenNumber DC.B AnEvenNumber
The first line produces just a named constant, and without the second, has no effect on your binary. The second line produces a byte in your binary, that contains the value designated by the named symbol constant.
Notice that the DC.B directive also allows an optional name; this symbol can also be used in other places in your code. Depending on the sophistication of your assembler, you may be able to define
LocationOfEvenNumber EQU MyEvenNumber
and
DC.W LocationOfEvenNumber
now producing a word in your binary file that "points" to your byte of binary data.
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