TYPE and LENGTHOF Operators


TYPE Operator
The TYPE operator returns the size, in bytes, of a single element of a variable.
Code Expression Value

 .data
 w   BYTE  ?
 x   WORD  ?
 y  DWORD  ?
 z  QWORD  ?
      
TYPE w 1
TYPE x 2
TYPE y 4
TYPE z 8
LENGTHOF Operator
The LENGTHOF operator counts the number of elements in an array, defined by the values appearing on the same line as its label.

If the first line of the array is ended with a comma and continues the list of initializers onto the next line, LENGTHOF regards the data from these two lines as part of the array.

 TYPE DWORD  TYPE DWORD 12 DUP(?)  LENGTHOF DWORD 12 DUP(?)
 .data
 var  DWORD  ?
 .code
 mov   eax, TYPE var
 call  WriteInt
 .data
 arr  DWORD  12 DUP(?)
 .code
 mov   eax, TYPE arr
 call  WriteInt
 .data
 arr  DWORD  12 DUP(?)
 .code
 mov  eax, LENGTHOF arr
 call WriteInt
 Output  Output  Output
   



   



   




 LENGTHOF BYTE \
  "12345", 0
 WORD 100h, 200h
 WORD 300h, 400h
 WORD 100h, 200h,
     300h, 400h
 .data
 s  BYTE  "12345", 0
 .code
 mov  eax, LENGTHOF s
 call WriteInt
 .data
 arr  WORD  100h, 200h
      WORD  300h, 400h
 .code
 mov  eax, LENGTHOF arr
 call WriteInt
 .data
 arr  WORD  100h, 200h,
            300h, 400h
 .code
 mov  eax, LENGTHOF arr
 call WriteInt
 Output  Output  Output