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
 INCLUDE Irvine32.inc
 .data
  s  BYTE  "Hello, world!"
  len = 
 .code
 main PROC 
  mov   eax, len
  call  WriteInt
  exit
 main ENDP
 END main
 
 INCLUDE Irvine32.inc
 .data
  a  WORD  10, 20, 30, 40
  len = 
 .code
 main PROC 
  mov   eax, len
  call  WriteInt
  exit
 main ENDP
 END main
 
 INCLUDE Irvine32.inc
 .data
  Dummy  WORD  ?
 .code
 main PROC
  
  add  eax, eax
  len = $ - a1
  mov   eax, len
  call  WriteInt
  exit
 main ENDP
 END main
 

Output Output Output
13 4 2

The 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 later in the program, it substitutes the integer value or text for the symbol. Code 3 and 4 are equal. stores the integer value 200, and stores the string “20 * 10” .
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

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

      “I’m not arguing, I’m just explaining why I’m right.”    
      ― Unknown