Memory Segmentation 8086

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3
At a glance
Powered by AI
The key takeaways are that 8086 uses memory segmentation to divide memory into logical segments and uses segment registers to access different segments.

The different memory segments in 8086 are code segment, data segment, extra segment, and stack segment.

In 8086, memory is divided into segments of maximum 64KB each. Segment registers contain the starting address of segments and instruction pointers like IP contain offset addresses to access locations within segments.

Memory Segmentation in 8086

The need of memory segmentation is explained below:

1. The BIU (Bus Interfacing Unit) contains four special purpose registers called as segment
registers. These are Code Segment (CS) register, Stack Segment (SS) register, Extra
Segment (ES) register and Data Segment (DS) register.
2. All these are 16 bit registers.
3. The number of address lines in 8086 is 20. So, the 8086 BIU will send out a 20 bit
address in order to access one of the 1,048,576 or 1MB memory locations.
4. But it is interesting to note that the 8086 does not work the whole 1MB memory at any
given time. However it works with only four 64 KB segments within the whole 1 MB
memory.
5. The four segment registers actually contain the upper 16 bits of the starting addresses of
the four memory segments of 64 KB each with which the 8086 is working at that instant
of time.
6. A segment is a logical unit of memory that may be up to 64 kilo bytes long.
7. Each segment is made up of memory contiguous memory locations. It is independent,
separately addressable unit.
8. Starting addresses will always be changing. They are not fixed.
9. Figure shows one of the possible ways to position the four 64 KB segments within the 1
MB memory space of 8086.
In 8086 processors, unlike the 8085, has the memory divided into various sections called as
segments. (Note that the following will be valid in 80286 and above for Real mode memory
addressing only.)

1. The first is the code segment where you store the program.
2. Second is data segment where the data is stored.
3. Third is extra segment which is mostly used for string operations.
4. Last one is the stack segment which is used to push/pop (save and retrieve) your data or
used to store addresses for RET when CALL is executed.

Now these segments are accessed by different pointers, no single pointer can access multiple
segments at the same time.

 The instruction pointer IP (similar to the program counter in 8085) is used to fetch the
code which holds the offset address and the starting of the segment address is held by the
CS i.e. code segment register.
 The DI/BX/SI register holds the offset address of the Data segment along with the DS i.e.
Data segment register holding the starting address of the data segment.
 Similarly the BP/SP has offset address of Stack segment and starting address is held by
SS i.e. stack segment register.
 The DI holds the offset address of Extra segment and starting address is held by SS
register.

Each segment has a capacity of 64 KB. These segments can be overlapped if they don’t need the
complete 64 KB space. It is interesting to note that this so called segmentation gives an essence
of Harvard-like Architecture. The advantage of segmentation is that the segments can be moved
anywhere as per need without affecting anything since the address is divided into two parts
where the code/data is accessed by the register holding the offset address. This is called as
relocation. Since not all PCs have same memory space, relocation is essential in general purpose
PCs which require relocatable program and data.

1. There is no restriction on the locations of these segments in the memory. These segments
can be separate from each other or they can overlap.
2. In the users program there can be many segments but 8086 can deal with only four of
them at any given time because it has only four segment registers.
3. Whenever the segment orientation is to be changed, the base addresses have to be
changed and load the upper 16 bits into the corresponding segment registers.
4. Segment registers are very useful for large programming tasks that require isolation of
program code from the data code or isolation of module data from the stack information
etc.
5. Segmentation builds relocatable and re-entrant programs easily. In many cases the task of
relocating a program simply requires moving the program code and then adjusting the
code segment register to point to the base of the new code area.
Advantages of memory segmentation:

1. Segmentation provides a powerful memory management mechanism.


2. It allows programmers to partition their programs into modules that operate
independently of one another.
3. Segments allow two processes to easily share data.
4. It allows to extend the address ability of a processor i.e. segmentation allows the use of
16 bit registers to give an addressing capability of 1 MB. Without segmentation, it would
require 20 bit registers.
5. Segmentation makes it possible to separate the memory areas for stack, code and data.
6. It is possible to increase the memory size of code data or stack segments beyond 64 KB
by allotting more than one segment for each area.

You might also like