3
1 MB
▪The memory in an 8086/88 based system is
organized as segmented memory.
▪The Complete physically available memory
may be divided into 16 logical segments.
▪But at any given time 8086 works with only
four 64 Kbytes segments within the 1 mega
byte of memory.
00000
FFFFF
Physical Memory
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Memory
00000H
FFFFFH
1MB
Address
Range
Code Segment
Stack Segment
Data & Extra
Segments
Only 4 Segments are accessible :
Functions :
–Code segment is used for storing the program
instructions.
–The stack segment is used to store the return
addresses (Main program sub program)
–The data and extra segments are used for storing
data bytes.
5
Segmented Memory
Data Segment Base
Top Of Data Segment
Top Of Code Segment
Code Segment Base
Stack Segment Base
Top Of Stack Segment
Extra Segment Base
Top Of Extra Segment
Highest Address
20000H
2FFFFH
348A0H
4489FH
50000H
5FFFFH
7FFFFH
FFFFFH
64KB
64KB
64KB
64KB
6
70000H
In 8086/88 the processors have 4 segments registers
•Each of the Segment registers store the upper 16 bit
address of the starting address of the corresponding
segments.
7
Segment registers
Segmented Memory
Data Segment Base
Top Of Data Segment
Top Of Code Segment
Code Segment Base
Stack Segment Base
Top Of Stack Segment
Extra Segment Base
Top Of Extra Segment
Highest Address
20000H
2FFFFH
348A0H
4489FH
50000H
5FFFFH
7FFFFH
FFFFFH
64KB
64KB
64KB
64KB
8
70000H
CSR = ????
DSR = ????
ESR = ????
SSR = ????
Segment Registers :
Holds the upper 16 bit of the
segment base.
Segmented Memory
Data Segment Base
Top Of Data Segment
Top Of Code Segment
Code Segment Base
Stack Segment Base
Top Of Stack Segment
Extra Segment Base
Top Of Extra Segment
Highest Address
20000H
2FFFFH
348A0H
4489FH
50000H
5FFFFH
7FFFFH
FFFFFH
64KB
64KB
64KB
64KB
9
70000H
CSR = 348A
DSR = 2000
ESR = 7000
SSR = 5000
Segment Registers :
Holds the upper 16 bit of the
segment base (Base address).
34BA
44EB
54EB
695E
10
CSR
DSR
ESR
SSR
Segment Registers
BIU
CODE (64k)
DATA (64K)
EXTRA (64K)
STACK (64K)
1
MB
00000
34BA0
44B9F
44EB0
54EAF
54EB0
64EAF
695E0
795DF
Each segment register store the upper 16 bit
of the starting address of the segments
MEMORY
FFFFF
34BA
44EB
54EB
695E
11
CSR
DSR
ESR
SSR
Segment Registers
BIU
CODE (64k)
DATA (64K)
EXTRA (64K)
STACK (64K)
1
MB
00000
34BA0
44B9F
44EB0
54EAF
54EB0
64EAF
695E0
795DF
Each segment register store the upper 16 bit
of the starting address of the segments
MEMORY
FFFFF
34BA
44EB
54EB
695E
Pointer & Index Register
•Following four registers are under this
category:
(1). Stack Pointer (SP),
(2). Base Pointer (BP),
(3). Source Index (SI),
(4). Destination Index (DI).
14
•Following Registers can also be used as a general
Purpose Registers.
(1). Stack Pointer (SP) & Base pointer (BP) is a 16-bit register
pointing to Stack, used to access the data in the stack .
It also contains 16-Bit offset address.
(2). Source Index (SI) is a 16-bit register. SI is as a source data
address in string manipulation Instructions
(3). Destination Index (DI) is a 16-bit register. DI is used as a
destination data address in string manipulation instructions.
Pointer & Index Register
15
•The instruction pointer (IP) contains a 16-bit offset address of
instruction that is to be executed next.
•CSR holds the base address of the CODE SEGMENT and the value
contained in IP is called as offset address.
•To form a 20bit address :
1) The 16 bit address of the IP
2) Base address of the Code segment(CS) Added
The IP always references the Code segment register (CS)
CS:IP
16
How a 20 bit address is generated ?
CODE SEGMENT
1
Data
Segment
3
4
Code
Segment
Extra
Segment
7
8
9
10
11
12
13
14
15
Stack
Segment
Memory
00000H
FFFFFH
1MB
Address
Range
348A H
4214 H
38AB4 H
CS
IP
Physical Address
Start of Code Segment
348A0H
Code Byte MOV AL, BL
38AB4H
IP = 4214H
+
0
∑(adder)
In the adder circuit, Code segment register is shifted
left 4 bits and then added to the IP (offset register).
•The following examples shows the CS:IP scheme
of address formation:
18
Inserting a hexadecimal 0H (0000B)
with the CSR or shifting the CSR
four binary digits left
3 4 B A 0 ( C S ) +
8 A B 4 ( I P )
3 D 6 5 4 (next address)
34BA 8AB4
CS IP
34BA0
3D645
44B9F
Code segment
8AB4 (offset)
19
1)If the Code segment Register (CS) is 1000H and IP (offset) is
2000H, then calculate the physical address:
PA = (1000H * 10) + 2000H = 12000H
So the physical address in the 8086 microprocessor would be 12000H
2) If the Data segment register (DS) is A4Fbh and the offset value (SI)
is 4872H, IP = 2890H then calculate the physical address:
PA = (A4FBh x 10) + 4872 = A9822H
So the physical address in the 8086 microprocessor would be A9822H
20
1)If the Code segment Register value is 1000H and IP (offset) is
2000H, then calculate the physical address:
PA = (1000H * 10) + 2000H = 12000H
So the physical address in the 8086 microprocessor would be 12000H
2) If the Data segment register value is A4Fbh and the offset value
(SI) is 4872H, IP = 2890H then calculate the physical address:
PA = (A4FBh x 10) + 4872 = A9822H
So the physical address in the 8086 microprocessor would be A9822H
21
22
CS:IP ( Code Segment )
CS = Segment Base
IP = Offset Value
CS + IP = 20-bit Physical Address
The Code Segment CS:IP
Memory
Segment Register
Offset
Physical or
Absolute Address
0
+
CS:
IP
4000H
0560H
40000H
40560H
4000
0560
40560H
The offset is given by the IP for the Code Segment.
Instructions are always fetched with using the CS register.
CS:IP = 4000:0560
Logical Address
00000
FFFFFH
The Stack Segment SS: SP
Memory
Segment Register
Offset
Physical Address
+
SS:
SP
0A00
0100
0A000H
0A100H
0A000
0100
0A100H
To access the stack we can use :
PUSH , POP
The offset is given by the SP register.
SS:SP
0H
0FFFFFH
SS:SP
SS:BP
The Data Segment DS:BX
Memory
Segment Register
Offset
Physical Address
+
DS:
BX
05C0
0050
05C00H
05C50H
05C00
0050
05C50H
Data is usually fetched with respect to the DS register.
The offset is given by the BX register.
DS:BX
0H
0FFFFFH
8086 – Default 16 bit segment and offset address
combinations
Segment offset special purpose
CS
SS
DS
ES
IP
SP (or) BP
BX,DI,SI
an 8-bit number
16 – bit number
DI for string
Instructions
Instruction
Address
Stack address
Data address
String destination
address
•Example For Address Calculation (segment:
offset)
•If the data segment starts at location 1000h and
a data reference contains the address 29h where
is the actual data?
27
Physical Address
Offset
Segment Address
0000000000101001
0000
0001 0000 0000 0010 1001
0001000000000000