Professional Documents
Culture Documents
Assembly Language
• The native language for all microprocessors is
machine language.
– However, machine language is very difficult to
deal with.
– Therefore, a matching symbolic language was
created – Assembly Language.
• The assembly language instructions are identical to
those of the processor’s machine language – except in
symbolic form.
• Each machine language instruction has a single unique
matching assembly language instruction (and vice
versa).
Example Instructions
ADD AX, BX ; Add variable X to Y
0100 CS
0200 DS 01100 8C MOV DX, CS
SS
ES 01101 CA
SP
BP 02000 xx
SI
DI 02001 xx
CS
DS 01100 8C MOV DX, CS
SS
ES 01101 CA
SP
BP 02000 xx
SI
DI 02001 xx
0100 CS
DS 01000 B0 MOV AH, 15H
SS
ES 01001 15
SP
BP
SI
DI
CS
DS 01000 B0 MOV AH, 15H
SS
ES 01001 15
SP
BP
SI
DI
AX 01004 xx
BX
xxxx CX 02000 xx
DX 02001 xx
SP 03234 ED
BP 03235 FE
SI
DI
AX 01004 xx
BX
CX 02000
DX 02001
SP 03234
BP 03235
SI
DI
SP 03234 ED
BP 03235 FE
1234H SI
DI
AX 01004 xx
BX
CX 02000 xx
DX 02001 xx
SP 03234 ED
BP 03235 FE
SI
DI
SP 03234 xx
BP 03235 xx
SI
DI
AX 01004 xx
BX
CX 02000
DX 02001
SP 03234
BP 03235
SI
DI
SP 03234 xx
BP 03235 xx
1234 SI
DI
AX 01004 xx
BX
CX 02000
DX 02001
SP 03234
BP 03235
SI
DI
SP 05234 BE
BP 05235 xx
2000 SI
DI
AX 01004 xx
BX
CX 02000
DX 02001
SP 05234
BP 05235
SI
DI
SP 06234 BE
BP 06235 ED
2000 SI
DI
AX 01004 xx
BX
CX 02000
DX 02001
SP 06234
BP 06235
SI
DI
MOV AX, CS
MOV DS, AX DS = 0000H
MOV AL, [BX]+1
PA = 00000 + 0040 + 1 = 00041 AL = 08
MOV AL, [SI]+TBL
PA = 00000 + 0002 + 0040 = 00042 AL = 07
MOV AL, [BX+SI]+1
PA = 00000 + 0040 + 0002 + 1 = 00043 AL = 06
PA = DS : {Direct}
⎧BX ⎫
⎪ ⎪
⎧ SS ⎫ ⎪ BP ⎪
PA = ⎨ ⎬ : ⎨ ⎬
⎩DS⎭ ⎪ SI ⎪
⎪⎩ DI ⎪⎭
⎧ SI ⎫ ⎧ 8 − bit displacement ⎫
PA = DS : ⎨ ⎬ + ⎨ ⎬
⎩DI⎭ ⎩16 − bit displacement ⎭
Destination Source
Memory Accumulator
Accumulator Memory
Register Register
Register Memory
Memory Register
Register Immediate
Memory Immediate
Seg-reg Reg16
Seg-reg Mem16
Reg16 Seg-reg
Mem16 Seg-reg
Assembler Directives
• EQU directive
LEN EQU 32
– Used for defining named constants.
– Everywhere the assembler sees the sequence
LEN in the following program, it will replace it with
32.
• This is done before instructions are translated to machine
code.
– Allows for quickly changing sizes of arrays or lists.
Assembler Directives
• DW Directive
MSG DW 4455H
– Define Word – reserve a sequence of words and set them to
the values indicated.
– The first byte will be reserved wherever this directive
appears relative to the ORG.
– Example:
ORG 1000H
CONST: DW 4455H
START: MOV AX, MSG
Assembler Directives
• RESW Directive
INPUT RESW 5
– Reserve a number of word sized memory
locations.
– This directive simply reserves the locations. It
does not set their contents.
– Useful for reserving storage space for values that
will be generated during program execution.
– Example usage:
ORG 1000H
INPUT: RESW 5
START: MOV AX, INPUT
MOV [AX], BX ; Save 16 bit value in reserved word