len: equ 2
len: db 2
Are they the same, producing a label that can be used instead of 2? If not, then what is the advantage or disadvantage of each declaration form? Can they be used interchangeably?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The first is
equate, similar to C’s:in that it doesn’t actually allocate any space in the final code, it simply sets the
lensymbol to be equal to 2. Then, when you uselenlater on in your source code, it’s the same as if you’re using the constant2.The second is
define byte, similar to C’s:It does actually allocate space, one byte in memory, stores a
2there, and setslento be the address of that byte.Here’s some pseudo-assembler code that shows the distinction:
Line 1 simply sets the assembly address to be
1234h, to make it easier to explain what’s happening.In line 2, no code is generated, the assembler simply loads
eleninto the symbol table with the value2. Since no code has been generated, the address does not change.Then, when you use it on line 4, it loads that value into the register.
Line 3 shows that
dbis different, it actually allocates some space (one byte) and stores the value in that space. It then loadsdleninto the symbol table but gives it the value of that address1234hrather than the constant value2.When you later use
dlenon line 5, you get the address, which you would have to dereference to get the actual value2.