;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Local Variables ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; DB[8] ByteArray ; DB ByteVar ; DB HELLO = 'HELLO',0 ; DB[4] InitArray = 0 ; DB InitializedVar = 1 ; DW[4] WordArray ; DW WordVar ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; NAME variable ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; variable.asm ; ; ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; Description: Shows how to declare different types of variables, as well as ; a few ways to access these variables. ; DGROUP GROUP DATA CGROUP GROUP CODE ; Variables in the code segment are constants (cannot be altered) CODE SEGMENT PUBLIC 'CODE' ASSUME CS: CGROUP, DS:DGROUP main: MOV AL, ByteVar ; load AL with ByteVar MOV AX, WordVar ; load AX with WordVar ;MOV AX, ByteVar ; illegal operation: different types MOV AL, ByteArray[2] ; AL = third element of the array LEA BX, ByteArray ; setup a pointer to the array MOV AL, [BX] + 2 ; AL = third element of the array LEA BX, ByteArray ; setup a pointer to the array MOV DI, 2 ; we use DI to index the array MOV AL, [BX][DI] ; AL = third element of the array LEA BX, ByteArray ; setup a pointer to the array MOV DI, 2 ; we use DI to index the array MOV AL, [BX][DI] + 2 ; AL = fifth element of the array MOV AL, [BX + DI + 2] ; same as the above statement MOV ByteVar, AL ; ByteVar = AL ;MOV WordVar, AL ; illegal operation: different types MOV WordVar, AX ; WordVar = AX LEA BX, ByteArray ; setup a pointer to the array MOV [BX], AL ; first element in array = AL LEA BX, ByteArray ; setup a pointer to the array MOV BYTE PTR [BX], 0 ; byte at [BX] = 0 MOV WORD PTR [BX], 0 ; word at [BX] = 0 ;MOV [BX], 0 ; illegal operation: move word or byte? HELLO DB 'HELLO',0 ; a constant null-terminated string CODE ENDS DATA SEGMENT PUBLIC 'DATA' ByteVar DB ? ; this variable is one byte (8 bits) WordVar DW ? ; this variable is one word (16 bits) InitializedVar DB 1 ; a variable initialized to 1 ; (do NOT do this in the data segment) ByteArray DB 8 DUP (?) ; this variable is the first of 8 bytes WordArray DW 4 DUP (?) ; this variable is the first of 4 words InitArray DB 4 DUP (0) ; an array initialized to zeroes ; (useful in some cases, but do not ; depend on this initialization) DATA ENDS END main