5.8086 Memory Segmentation
5.8086 Memory Segmentation
2
Description of Address Registers
7
8
Figure : The 8086 memory segments.
• A segment starts at a particular address and its maximum
size can go up to 64 Kbytes. But if another segment starts
along this 64Kbytes location of the first segment, the two
segments are said to be overlapping segment.
Figure : Overlapping of the 8086 memory segments.
SEGMENTATION AND OFFSET
Book chapter: Ytha yu 3.2.3 Segment Registers
Memory Segment
A memory segment is a block of 64 KB memory blocks. Each
segment is identified by a segment number, starting with 0000H. A
segment number is 16 bits, so the highest segment number is FFFFH.
Within a segment, a memory location is specified by an offset. This
is the number of bytes from the beginning of the segment. The first
byte in a segment has offset 0. The last offset in a segment is FFFFH.
6 Oct. 2010
4
SEGMENT
REGISTERS
- Each of these segments are addressed by an
address stored in corresponding segment register.
- These registers are 16-bit in size.
- Each register stores the base address
(starting address) of the corresponding
segment.
- Because the segment registers cannot store 20
bits, they only store the upper 16 bits.
5
6
SEGMENT REGISTERS
Q: How is a 20-bit address obtained if there are
only 16-bit registers?
The 20-bit address is called Physical Address.
The 16-bit address is called Logical Address.
Logical address is in the form of:
Base Address : Offset
Offset is the displacement of the memory location
from the starting location of the segment.
Thus a memory location may be specified by providing
the 16-bit segment base address, and a 16-bit offset,
written in the form
segment : offset; this is known as a logical address for7
the memory location.
SEGMENT REGISTERS
For example, the logical address A4FBH : 4872H means
offset 4872H within segment A4FBH, that is, the segment
starting at physical address A4FB0H.
To obtain the corresponding 20-bit physical (i.e., absolute)
address, the 8086 microprocessor first shifts the segment
base address 4 bits to the left (this is equivalent to multiplying
by 10H), and then adds the offset. Thus the physical address
for A4FB:4872h is:
A4FB0h
+ 4872h
A9822h (20-bit physical address)
10
Left shift 3 bit
Bits positions
vacated by shift are
filled with zeros
10
EXAMPLE
9
EXAMPLE
The value of Code Segment Register (CS) is 2222 H
Convert this 16-bit address into 20-bit,
The starting address of the Code Segment becomes
22220H
8
EXAMPLE (CONTD.)
Therefore:
2222 * 10 H
+ 0016 H
------------
Physical
address = 22236 H
11
2222 H BYTE – 0
22220 H
BYTE – 1
CS Register
BYTE – 2
-
offset = 0016 -
H -
-
-
22236 H
EXAMPLE (CONTD.)
Addressed Byte
12
Figure : The 8086 memory-addressing, using a segment address plus an offset.
Segment: Offset Address (Logical Address)
To obtain a 20 bit physical address,
• - Shift the segment address 4 bit to
the left ( i.e. multiply by 10h)
• - Add the offset
Example:
Segment : offset = A4FB:4872h
Physical address
= segment number * 10h + offset
= A4FBh * 10h + 4872h = A9822h
14
QUESTION
The contents of the following registers are:
CS = 1111 H
DS = 3333 H
SS = 2526 H
IP = 1232 H
SP = 1100 H
DI = 0020 H
Calculate the corresponding physical addresses
for the address bytes in CS, DS and SS.
15
SOLUTIO
1. CS = 1111 H N
The base address of the code segment is 11110 H.
Physical address of memory is given by 11110H +
1232H = 12342H.
2. DS = 3333 H
The base address of the data segment is 33330 H.
Physical address of memory is given by 33330H +
0020H = 33350H.
3. SS = 2526 H
The base address of the stack segment is 25260 H.
Physical address of memory is given by 25260H + 16
1100H = 26360H.
Because segments may overlap, the segment : offset form
of an address is not unique for a particular memory
location as is the case for the physical address of that
memory location.
Example 3.1 For the memory location whose
physical address is specified by 1256Ah, give
the address in segment : offset for segments
1256h and 1240h
33
Example 3.1 For the memory location whose physical address is
specified by 1256Ah, give the address in segment : offset for segments
1256h and 1240h
Solution:
Physical address = segment number * 10h + offset
=> 1256AH = 1256h * 10H + offset
=> Offset = 1256AH – 12560H = AH
So, 1256AH = 1256 H : 000AH
Physical address = segment number * 10h + offset
=> 1256AH = 1240H * 10H + offset
=> Offset = 1256AH – 12400H = 16AH
So, 1256AH = 1240 H : 016AH
34
Segment: Offset Address (Logical Address)
35
Segment: Offset Address (Logical Address)
36