Syntax for a variable declaration: name DB value name DW value DB - stays for Define Byte. DW - stays for Define Word. name - can be any letter or digit combination, though it should start with a letter. It's possible to declare unnamed variables by not specifying the name (this variable will have an address but no name). value - can be any numeric value in any supported numbering system (hexadecimal, binary, or decimal), or "?" symbol for variables that are not initialized. |
ORG 100h MOV AL, var1 MOV BX, var2 RET ; stops the program. VAR1 DB 7 var2 DW 1234h |
ORG 100h DB 0A0h DB 08h DB 01h DB 8Bh DB 1Eh DB 09h DB 01h DB 0C3h DB 7 DB 34h DB 12h |
BYTE PTR [BX] ; byte access. or WORD PTR [BX] ; word access.assembler supports shorter prefixes as well:
ORG 100h MOV AL, VAR1 ; check value of VAR1 by moving it to AL. LEA BX, VAR1 ; get address of VAR1 in BX. MOV BYTE PTR [BX], 44h ; modify the contents of VAR1. MOV AL, VAR1 ; check value of VAR1 by moving it to AL. RET VAR1 DB 22h END |
ORG 100h MOV AL, VAR1 ; check value of VAR1 by moving it to AL. MOV BX, OFFSET VAR1 ; get address of VAR1 in BX. MOV BYTE PTR [BX], 44h ; modify the contents of VAR1. MOV AL, VAR1 ; check value of VAR1 by moving it to AL. RET VAR1 DB 22h END |
name EQU < any expression >
k EQU 5 MOV AX, k |
MOV AX, 5 |