L4 8086 Segmentation
L4 8086 Segmentation
Microprocessor
Memory
Segmentation
Background
3
Memory Segmentation
10000H
10001H
. 64K Memory region to store code (instructions)
.
1FFFFH
20000H
20001H
. 64K Memory region to store data (Eg: variables)
.
2FFFFH
4
How to Segment?
Eg:
0x1000 0x1FF0
CS IP
9
Example Segmented Memory
Address
20000H 2000
DS
Data segment
2FFFFH 348A
348A0H
CS
Code segment
4489FH
50000H
5000
SS Stack Segment
5FFFFH
70000H
7000 Extra segment
ES
7FFFFH 10
Bottom of data segment
Memory
Generation of Physical Memory Address
Immediate addressing:
MOV BYTE PTR [2000],35
o Default segment register is data segment (DS)
o 35H is copied to (DS<<4)+2000H
o This instruction can be written with explicit segment register also
MOV BYTE PTR DS:[2000],35
o The default segment can be overridden by explicitly specifying it
MOV BYTE PTR ES:[2000],35
o 35H is copied to (ES<<4)+2000H
12
Quick review of addressing modes
Direct/Displacement addressing:
MOV CX,[23FE]
o Default segment register is data segment (DS)
o Data is copied from (DS<<4)+23FEH to CX
o Default segment can be over-ridden
MOV CX,SS:[23FE]
Register Indirect addressing:
o BX, DI and SI use DS as the default segment register
o BP uses stack segment
MOV AX,[BX]; physical address is (DS<<4)+BX
13
MOV AX,[BP]; physical address is (SS<<4)+BP
Quick review of addressing modes
14
Caution!!
15
Caution!!
o What processor does is; it will only take 16-bits of offset for adding
with segment register
o If offset contains more than 16-bits, it will drop the MS bits (upper
bits)
o For previous example, total offset
BX+1F2E = E200+1F2E = 1012E
o Since 1012E contains 17 bits, MS bit is dropped and offset is taken
as 012E
o Thus, physical address is
DS<<4+012E = 2012E, which is with in the segment
o Similar approach is taken if the final physical address calculated has16
pgm1.asm pgm2.asm
o Store both programs at address 10000H and 20000H and store
1000H in CS while executing program1 and 2000H in CS while
18
executing program2
Other Advantages of Segmentation: Multi-
tasking
10000H
pgrm1
CS 20000H
pgrm2
IP
8086
RAM 19
Other Advantages of Segmentation: Multi-
tasking
10000H
pgrm1
1000
CS 20000H
0000 pgrm2
IP
8086
10000H
pgrm1
2000
CS 20000H
0000 pgrm2
IP
8086
22