Slide-3 (Memory Segmentation)
Slide-3 (Memory Segmentation)
Interfacing
EEE 315
Fahim Mahmud
Assistant Professor
Dept. of EEE
CUET
Class outline
https://www.youtube.com/watch?v=i95AiGQqR3Y
https://youtu.be/XX9rDGTBGgQ Architecture
Why memory segmentation?
From 8086 point of view, the idea of dividing the whole 1MB memory into 4
segments namely code, data, stack and extra segment is called memory
segmentation.
This is done by splitting the actual 20 bit address in segment address and
offset address.
The 20 bit address is called physical address (PA) and is never directly used
by us, the programmers. The microprocessor calculates it while doing its
operation.
We, the programmers, work with virtual address (segment address and
offset address).
8085 had no memory segmentation because its address bus was 16 bit
which was already byte compatible (2 bytes).
Types of addresses
Since offset address is of 16 bits, its max value is FFFFH, which is 64kB.
So, the maximum size of a segment can be 64kB.
Since segment address cannot be fractional, so if the starting address is
0000H, immediate next address will be 0001H.
Therefore, minimum size of segment is 10H, that is 16 bytes.
In summary, max segment size = 64kB, min segment size = 16 bytes.
Memory segmentation in 8086
Segments in 8086
Code segment: It’s used to store the programs. The CS register in the 8086
holds the 16-bit base/segment/starting address of this segment. The IP
(Instruction Pointe) register holds the offset address of the next instruction to
be fetched and executed.
Data segment: This segment is used to store general data. The DS register
holds its segment/base address and the BX register holds the offset address.
The SI (Source Index) register holds the offset address during string
operations.
Segments in 8086
Stack segment: This segment is also used to store general data. It works in
LIFO manner (Last In First Out). SS register holds its base address. SP (Stack
Pointer) register holds the offset address that points to the top of the stack.
BP (Base Pointe) register holds the offset address for random access to the
stack. SMS can be a good example of stack memory. Each new message is
stacked on top of the last one. The last SMS is shown by default, that is the
SP points to the top of the stack. By using the BP, we can locate any
messages within the stack.
Extra segment: This segment is used to store general data as well. ES register
holds its base address and DI (Destination Index) register holds the offset
address during string operations.
Advantages and disadvantages of
memory segmentation
It permits the programmer to access 1MB memory using only 16-bit address.
It divides the memory logically to store instructions, data and stack
separately.