8086 Lecture Notes 3
8086 Lecture Notes 3
ASSEMBLY LANGUAGE
PROGRAMMING
Source Operand
ADD AX, BX
Format of an assembly statement:
LABEL: INSTRUCTION
e.g.
; COMMENT
; Copy BX into AX
ASSEMBLY LANGUAGE
PROGRAMMING
PAGE
,132
SEGMENT
64 DUP(?)
ENDS
;Bytes to be moved
;Source block offset address
;Destination block offset addr
;Data segment start address
STACK 'STACK'
CODE_SEG
SEGMENT
'CODE'
BLOCK
PROC
FAR
ASSUME CS:CODE_SEG,SS:STACK_SEG
STACK_SEG
SEGMENT
DB
64 DUP(?)
8A 24
88 25
46
47
49
75 F7
CB
Attr
0100h
0120h
2000h
0013
0010h
Private 'CODE'
Stack
'STACK'
CODE_SEG
Length= 001D
CODE_SEG
STACK 'STACK'
Attr
0000
Combine Class
STACK_SEG
ENDS
CODE_SEG
SEGMENT
'CODE'
BLOCK
PROC
FAR
ASSUME CS:CODE_SEG,SS:STACK_SEG
Para
Para
]
0040
0000
0000
Length Align
DB 64 DUP(?)
e.g.
Size
12/14/02 15:10:26
Symbols 2 - 1
Describe problem
Move an element from
source to destination block
Plan steps of
solution
Flowchart
Implement flowchart
using assembler language
Hand-written source program
No
All elements
Moved?
Yes
End
(Return to DEBUG)
Object module
Connection
within
a flowchart
Process
Connection
to another
flowchart
Decision
Yes
Logic errors?
No
Handwritten
source program
EDIT
Editor program
PROG1.ASM
AX, DATASEGMENT
DS, AX
SI, BLK1ADDR
DI, BLK2ADDR
CX, N
MASM
Assembler program
PROG1.OBJ
Libraries
The directive
[Example]
LINK
linker program
PROG1.LST
Other.OBJ files
PROG1.EXE
DEBUG
Debug program
BLOCK
PROC
BLOCK
ENDP
FAR
Final debugged
run module
or
object module
The Microsoft MASM assembler
The Microsoft PWB (Programmers Work Bench)
The assembler source file and the object
module
PROG1.MAP
development cycle
PROG1.ASM
PROG1.OBJ
PROG1.LST
PROG1.EXE
PROG1.MAP
(Editor)
(Assembler)
(Assembler)
(Linker)
(Linker)
Logic instructions
Arithmetic instructions
Arithmetic instructions
Meaning
Format
Operation
Flags affected
MOV
Move
MOV D, S
(S) (D)
None
e.g.
MOV DX, CS
MOV [SUM], AX
Source
Memory
Accumulator
Accumulator
Memory
Register
Register
Register
Memory
Memory
Register
Register
Immediate
Memory
Immediate
Seg-reg
Reg16
Seg-reg
Mem16
Reg16
Seg-reg
Memory
Seg-reg
IP
0100
0200
CS
DS
SS
ES
XXXX
AX
BX
CX
DX
Address Memory
Content
01100
01101
01102
8C
CA
XX
02000
02001
XX
XX
Instruction
MOV DX, CS
Next instruction
SP
BP
SI
DI
8088/8086 MPU
Before execution
MOV DX, CS
Address
0102
IP
0100
0200
CS
DS
SS
ES
AX
BX
CX
DX
0100
Address Memory
Content
01100
01101
01102
8C
CA
XX
02000
02001
XX
XX
Instruction
MOV DX, CS
0000
0100
Next instruction
XXXX
ABCD
SP
BP
SI
DI
IP
CS
DS
SS
ES
01000
01001
01002
Memory
Content
8B
C3
XX
Instruction
MOV AX, BX
Next instruction
AX
BX
CX
DX
SP
BP
SI
DI
8088/8086 MPU
8088/8086 MPU
After execution
Before execution
Address
0002
IP
0100
CS
DS
SS
ES
ABCD
ABCD
01000
01001
01002
Memory
Content
8B
C3
XX
Instruction
MOV AX, BX
Next instruction
AX
BX
CX
DX
SP
BP
SI
DI
8088/8086 MPU
After execution
0100
Operand Sizes
Byte (Reg 8)
Accumulator
AL, AH
AX
Base
BL, BH
BX
Count
CL, CH
CX
Data
DL, DH
DX
Stack pointer
SP
Base pointer
BP
Source index
Destination index
DI
Code segment
CS
Data segment
DS
Stack segment
SS
Extra segment
ES
Address
0000
SI
XX
IP
CS
DS
SS
ES
01000
01001
01002
01003
Memory
Content
B0
15
XX
XX
Instruction
AX
BX
CX
DX
SP
BP
SI
DI
8088/8086 MPU
Before execution
611 37100 Lecture 03-42
0002
IP
0100
15
0000
MOV AL, 15H
Next instruction
AX
BX
CX
DX
0100
0200
XXXX
SP
BP
SI
DI
Instruction
8B
0E
34
12
XX
02000
02001
.
.
.
.
03234
03235
XX
XX
IP
CS
DS
SS
ES
AX
BX
CX
DX
SP
BP
SI
DI
8088/8086 MPU
Memory
Content
01000
01001
01002
01003
01004
Address
Instruction
B0
15
XX
XX
01000
01001
01002
01003
CS
DS
SS
ES
Memory
Content
Next instruction
ED
BE
Source operand
8088/8086 MPU
After execution
Before execution
IP
0100
0200
CS
DS
SS
ES
CS
SS
PA= DS
ES
BX
BP
SI
DI
8-bit displacement
16-bit displacement
Memory
Content
Instruction
01000
01001
01002
01003
01004
8B
0E
34
12
XX
02000
02001
.
.
.
.
03234
03235
XX
XX
Address
0004
BEED
AX
BX
CX
DX
SP
BP
SI
DI
Next instruction
ED
BE
Source operand
8088/8086 MPU
After execution
CS
SS
PA= DS
ES
SS
BP
PA= DS : SI
CS
: Direct address
BX
ES
DI
e.g.
e.g.
IP
0100
0200
CS
DS
SS
ES
XXXX
AX
BX
CX
DX
01000
01001
01002
02000
02001
.
.
.
.
03234
03235
SP
BP
SI
DI
1234
Address Memory
Content
8B
04
XX
0000
MOV AX, [SI]
Next instruction
IP
0100
0200
CS
DS
SS
ES
BE ED
1000
AX
BX
CX
DX
XX
XX
ED
BE
Address Memory
Content
Instruction
SP
BP
SI
DI
Source operand
8088/8086 MPU
8088/8086 MPU
Before execution
01000
01001
01002
01003
01004
88
87
34
12
XX
02000
02001
.
.
.
.
04234
04235
XX
XX
XX
XX
Before execution
Instruction
MOV [BX]+1234H, AL
Next instruction
Destination operand
IP
0100
0200
CS
DS
SS
ES
BEED
AX
BX
CX
DX
01000
01001
01002
02000
02001
.
.
.
.
03234
03235
SP
BP
SI
DI
1234
Address Memory
Content
8B
04
XX
0004
MOV AX, [SI]
Next instruction
IP
0100
0200
CS
DS
SS
ES
BE ED
1000
AX
BX
CX
DX
XX
XX
ED
BE
Address Memory
Content
Instruction
SP
BP
SI
DI
Source operand
8088/8086 MPU
8088/8086 MPU
After execution
01000
01001
01002
01003
01004
88
87
34
12
XX
02000
02001
.
.
.
.
04234
04235
XX
XX
ED
XX
After execution
Instruction
MOV [BX]+1234H, AL
Next instruction
Destination operand
CS
SS
PA= DS
ES
: BX
BP
8-bit displacement
+ 16-bit displacement
CS
SS
SI
PA= DS : DI
ES
Memory
Memory
Element n
Element
n-1
Element n
Element n-1
Displacement
Array of data
Element
2
Element 1
Element 0
Displacement
Array of data
Element 2
Element 1
Element 0
Base register
Index register
e.g.
8-bit displacement
+ 16-bit displacement
MOV [BX]+1234H, AL
e.g.
IP
0100
0200
AX
BX
CX
DX
Instruction
0000
MOV AL, [SI]+1234H
CS
DS
SS
ES
XX XX
1000
AX
BX
CX
DX
2000
BE
Source operand
8088/8086 MPU
IP
0100
0200
Next instruction
XX
XX
02000
02001
.
.
.
.
05234
SP
BP
SI
DI
2000
8A
84
34
12
XX
01000
01001
01002
01003
01004
CS
DS
SS
ES
XX XX
Address Memory
Content
SP
BP
SI
DI
Address Memory
Content
01000
01001
01002
01003
01004
8A
A0
34
12
XX
02000
02001
.
.
.
.
06234
XX
XX
BE
Instruction
MOV AH,
[BX][SI]+1234H
Next instruction
Source operand
8088/8086 MPU
Before execution
Before execution
IP
0100
0200
CS
DS
SS
ES
XX BE
AX
BX
CX
DX
8A
84
34
12
XX
01000
01001
01002
01003
01004
Instruction
0004
MOV AL, [SI]+1234H
CS
DS
SS
ES
BE XX
1000
AX
BX
CX
DX
Next instruction
2000
BE
Source operand
8088/8086 MPU
IP
0100
0200
XX
XX
02000
02001
.
.
.
.
05234
SP
BP
SI
DI
2000
Address Memory
Content
SP
BP
SI
DI
Address Memory
Content
01000
01001
01002
01003
01004
8A
A0
34
12
XX
02000
02001
.
.
.
.
06234
XX
XX
BE
Instruction
MOV AH,
[BX][SI]+1234H
Next instruction
Source operand
8088/8086 MPU
After execution
After execution
611 37100 Lecture 03-59
PA=
BX
SI
: BP
+ DI
8-bit displacement
16-bit displacement
Memory
Element (m,n)
Element (m,1)
Element (m,0)
Element (1,1)
Element (1,0)
Element (0,n)
Element (0,1)
Element (0,0)
Index register
+
Base register
+
Displacement
Two dimensional
Array of data
e.g.
10