Integer Declaration 

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.

The syntax is: [[name]] directive initializer

Defining and Using Simple Data Types:

The following directives indicate the integer’s size and range of values:

Directive Alternative Form Number Type Size(bytes)Range
BYTE DB (byte) unsigned 1 0 to 255.
SBYTE signed 1 –128 to +127.
WORD DW unsigned 2 0 to 65,535 (64K).
SWORD signed 2 –32,768 to +32,767.
DWORD DD unsigned 4 0 to 4,294,967,295 (4 Gegabytes).
SDWORD signed 4 –2,147,483,648 to +2,147,483,647.
FWORD DF 48-bit integer6
QWORD DQ 8-byte integer8used with 8087-family
TBYTE DT 80-bit integer10long integer

 Byte Storage Order

Data Initialization:

Variables can be initialized at declaration with constants or expressions that evaluate to constants.
A ? in place of an initializer indicates that you do not require the assembler to initialize the variable. The assembler allocates the space but does not write in it.

Variables may be declared and initialized in one step with the data directives. The following examples show different declarations and initilizations:

Variable declarations and initilizations
integer		BYTE	16 	
negint		SBYTE	-16 	
expression	WORD	4*3 	
signedexp	SWORD	4*3 	
empty		QWORD	? 	
num		BYTE	1,2,3,4,5,6 	
long		DWORD	4294967295 	
lngnum		SDWORD	-2147433648	
tb		TBYTE	2345t		

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 256 
causes 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 -200
stores 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:

Data Type Bytes


This example illustrates the use of the TYPE operator.

The Type Operator
		var1	db	20h
		var2	dw	1000h
		var3	dd	?
		var4	db	10, 20, 30, 40, 50
		msg	db	‘File not found’, 0
	L1:	mov ax, type var1		; AX = 0001
   		mov ax, type var2		; AX = 0002
  	 	mov ax, type var3		; AX = 0004
   		mov ax, type var4		; AX = 0001
   		mov ax, type msg		; AX = 0001
   		mov ax, type L1		; AX = FFFF

The data types SBYTE, SWORD, and SDWORD tell the assembler to treat the initializers as signed data.