| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Declaring Integer Variables:An integer is a whole number, such as 4 or 4,444. Integers have no fractional part. Integer variables can be initialized in several ways with the data allocation directives. Allocating Memory for Integer Variables:When an integer variable is declared, the assembler allocates memory space for the variable. The variable’s name becomes a reference to the memory space allocated to that variable.
Defining and Using Simple Data Types:The following directives indicate the integer’s size and range of values:
Data Initialization:
Variables can be initialized at declaration with constants or expressions
that evaluate to constants.
Variables may be declared and initialized in one step with the data directives. The following examples show different declarations and initilizations:
Note that using a value that is outside the specified range can result either in an assembler error, or in assigning a wrong value. For example, the statement byte1 DB 256causes an assembly time error. In general, the assembler can accept a value in the range -256 to +255. However, 8 bits are not sufficient for the values between -256 and -129. Therefore, the assembler converts the number into 2's complement representation using 16 bits and stores the lower byte. For example, byte2 DB -200stores 38H because the 2's complement representation of -200 is FF38H. For information on arrays and on using the DUP operator to allocate initializer lists, see “Arrays and Strings”in later unit. SIZEOF and TYPE operators:The TYPE operator returns the size (in bytes) of a single element of a variable. For variables, it is 1, 2 or 4 for bytes, words and doublewords respectively. When applied to a label, the TYPE operator returns the value FFFFh for near labels, and FFFEh for far labels . The SIZEOF and TYPE operators, when applied to a type, return the size of an integer of that type. The size attributes associated with each data type are:
Example:This example illustrates the use of the TYPE operator.
The data types SBYTE, SWORD, and SDWORD tell the assembler to treat the initializers as signed data. |