Calculating Data Sizes and EQU Directive


The ‘$’ operator (current location counter) returns the offset associated with the current program statement.

 String Size   Array Size   Instruction Size 

 .data
 s  BYTE  "Hello, world!"
 len = 
 .code
 mov   eax, len
 call  WriteInt
 


 .data
 a  WORD  10, 20, 30, 40
 len = 
 .code
 mov   eax, len
 call  WriteInt
 


 .code
 
 add  eax, eax
 len = $ - a1
 mov   eax, len
 call  WriteInt
 

 Output  Output  Output
  13     4     2  

The EQU directive associates a symbolic name with an integer expression or some text.

 name  EQU  expression
 name  EQU  symbol
 name  EQU  <text>
When the assembler encounters name later in the program, it substitutes the integer value or text for the symbol. Code 3 and 4 are equal. myWord1 stores the integer value 200, and myWord2 stores the string “20 * 10” .

Unlike the ‘=’ directive, a symbol defined with EQU cannot be redefined in the same source code.
Code
3

 myInt     EQU   20 * 10
 myString  EQU   <20 * 10>
 .data
 myWord1   WORD  myInt
 myWord2   WORD  myString
      
Code
4

 .data
 myWord1   WORD  200
 myWord2   WORD  20 * 10