Embedded Systems and
Interfacing
EEE 315
Fahim Mahmud
Assistant Professor
Dept. of EEE
CUET
Class outline
Why memory segmentation?
What is memory segmentation?
Memory segmentation in 8086
https://www.youtube.com/watch?v=i95AiGQqR3Y
https://youtu.be/XX9rDGTBGgQ Architecture
Why memory segmentation?
Memory stores data and program.
Without any boundary in between, they may overlap.
Furthermore, 8086 has a 20-bit address bus (2.5 bytes). It’s not byte-
compatible.
Meaning, to store a memory address while writing a program, we need 2
and a half bytes. The other half byte will be wasted.
To address the above problem, specifically the second one that is byte
incompatibility, the idea of memory segmentation arises.
Memory segmentation is done by the assembler and managed by the
microprocessor.
This idea can loosely be correlated with the idea of having files and folders
where the contents of one file or folder don’t overlap with others.
What is 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
Physical address (never given by the programmer)
Segment address (given once while writing program)
Offset address (always given while writing programs)
Segment address and offset addresses are 16 bits each.
Physical address = 10*segment address + offset address
Size of segments
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.
At a time only 4*64kB memory can used (considering the 4 segments)