When applied to an array, the LENGTHOF, SIZEOF, and TYPE operators
return information about the length and size of the array and
about the type of the initializers.
The LENGTHOF operator:
The LENGTHOF operator returns the number of elements in an array.
The following example illustrates the use of the LENGTHOF operator:
Example: LENGTHOF Operator |
.data
;declaration of arrays
array_1 WORD 40 DUP (5)
num DWORD 4, 5, 6, 7, 8, 9, 10, 11
warray WORD 40 DUP (40 DUP (5))
;array array_1
larray EQU LENGTHOF array ; 40 elements
;array num
lnum EQU LENGTHOF num ; 8 elements
;array_1 warray
len EQU LENGTHOF warray ; 1600 elements
|
The SIZEOF operator:
The SIZEOF operator returns the number of bytes used by the
initializers in the definition of an array.
The following example illustrates the use of the SIZEOF operator:
Example 2: SIZEOF Operator |
.data
;declaration of arrays
array_1 WORD 40 DUP (5)
num DWORD 4, 5, 6, 7, 8, 9, 10, 11
warray WORD 40 DUP (40 DUP (5))
;array array_1
sarray EQU SIZEOF array ; 80 bytes
;array num
snum EQU SIZEOF num ; 32 bytes
;array_1 warray
siz EQU SIZEOF warray ; 3200 bytes
|
The TYPE operator:
TYPE returns the size of the elements of an array.
The following examples illustrate the use of the TYPE operator:
Example 3: TYPE Operator |
.data
;declaration of arrays
array_1 WORD 40 DUP (5)
num DWORD 4, 5, 6, 7, 8, 9, 10, 11
warray WORD 40 DUP (40 DUP (5))
;array array_1
tarray EQU TYPE array ; 2 bytes per element
;array num
tnum EQU TYPE num ; 4 bytes per element
;array_1 warray
typ EQU TYPE warray ; 2 bytes per element
|
|