When you declare an integer variable by assigning a label to a data allocation directive, the assembler allocates memory space for the integer. The variable's name becomes a label for the memory space. The syntax is
[[name]] directive initializer
These directives, listed below, indicate the integer's size and value range.
Directive | Description of Initializers |
BYTE, DB (bytes) | Allocates unsigned numbers from 0 to 255. |
SBYTE (signed bytes) | Allocates signed numbers from –128 to +127. |
WORD, DW (words = 2 bytes) | Allocates unsigned numbers from 0 to 65,535 (64K). |
SWORD (signed words) | Allocates signed numbers from –32,768 to +32,767. |
DWORD, DD (doublewords = 4 bytes) | Allocates unsigned numbers from 0 to 4,294,967,295 (4 megabytes). |
SDWORD (signed doublewords) | Allocates signed numbers from –2,147,483,648 to +2,147,483,647. |
FWORD, DF (farwords = 6 bytes) | Allocates 6-byte (48-bit) integers. These values are normally used only as pointer variables on the 80386/486 processors. |
QWORD, DQ (quadwords = 8 bytes) | Allocates 8-byte integers used with 8087-family coprocessor instructions. |
TBYTE, DT (10 bytes) | Allocates 10-byte (80-bit) integers if the initializer has a radix specifying the base of the number. |
See Chapter 6 for information on the REAL4, REAL8, and REAL10 directives that allocate real numbers.
Summary: The assembler enforces only the size of initializers.
MASM does not enforce the range of values assigned to an integer. If the value does not fit in the space allocated, however, the assembler generates an error.
The SIZEOF and TYPE operators, when applied to a type, return the size of an integer of that type. The following list gives the size attribute associated with each data type.
Data Type | Bytes |
BYTE, SBYTE | 1 |
WORD, SWORD | 2 |
DWORD, SDWORD | 3 |
FWORD | 6 |
QWORD | 8 |
TBYTE | 10 |
The SBYTE, SWORD, and SDWORD data types are new to MASM 6.0. Use of these signed data types tells the assembler to treat the initializers as signed data. It is important to use these signed types with high-level constructs such as .IF, .WHILE, and .REPEAT (see Section 7.2.1, “Loop-Generating Directives”), and with PROTO and INVOKE directives (see Sections 7.3.6, “Declaring Procedure Prototypes,” and 7.3.7, “Calling Procedures with INVOKE”).
The assembler stores integers with the least significant bytes lowest in memory. Note that assembler listings and most debuggers show the bytes of a word in the opposite order—high byte first.
Figure 4.1 illustrates the integer formats.
Summary: TYPEDEF can define integer aliases.
Although the TYPEDEF directive's primary purpose is to define pointer variables (see Section 3.3.1), you can also use TYPEDEF to create an alias for any integer type. For example, these declarations
char TYPEDEF SBYTE
longint TYPEDEF DWORD
float TYPEDEF REAL4
double TYPEDEF REAL8
allow you to use char, longint, float, or double in your programs if you prefer the C data labels.