Assembly Language Programming
Assembly Language Programming
Program Statements
name operation operand(s) comment
Space or tab separates initial fields Comments begin with semicolon Most assemblers are not case sensitive
Defining Data
Numeric data values
100 - decimal 100B - binary 100H - hexadecimal '100' - ASCII "100" - ASCII
ANum refers to a byte storage location, initialized to FCh The next word has no associated name ONE and UNO refer to the same word X is an unitialized doubleword
Arrays
Any consecutive storage locations of the same size can be called an array
X DW 40CH,10B,-13,0 Y DB 'This is an array' Z DD -109236, FFFFFFFFH, -1, 100B Components of X are at X, X+2, X+4, X+8 Components of Y are at Y, Y+1, , Y+15 Components of Z are at Z, Z+4, Z+8, Z+12
DUP
Allows a sequence of storage locations to be defined or reserved Only used as an operand of a define directive
DB DW DB db 40 DUP (?) 10h DUP (0) 3 dup ("ABC") 4 dup(3 dup (0,1), 2 dup('$'))
Word Storage
Word, doubleword, and quadword data are stored in reverse byte order (in memory)
Directive DW 256 DD 1234567H DQ 10 X DW 35DAh Bytes in Storage 00 01 67 45 23 01 0A 00 00 00 00 00 00 00 DA 35
Named Constants
Symbolic names associated with storage locations represent addresses Named constants are symbols created to represent specific values determined by an expression Named constants can be numeric or string Some named constants can be redefined No storage is allocated for these values
EQU Directive
name EQU expression
expression can be string or numeric Use < and > to specify a string EQU these symbols cannot be redefined later in the program sample EQU 7Fh aString EQU <1.234> message EQU <This is a message>
reg can be any nonsegment register except IP cannot be the target register MOV's between a segment register and memory or a 16-bit register are possible
When a variable is created with a define directive, it is assigned a default size attribute (byte, word, etc) You can assign a size attribute using LABEL
LoByte LABEL BYTE aWord DW 97F2h
eXCHanGe
XCHG target, source
reg, reg reg, mem mem, reg
Arithmetic Instructions
ADD dest, source SUB dest, source INC dest DEC dest NEG dest Operands must be of the same size source can be a general register, memory location, or constant dest can be a register or memory location
except operands cannot both be memory
Stack Segment
used to set aside storage for the stack Stack addresses are computed as offsets into this segment
Code Segment
contains executable instructions