8086, via its 20-bit address bus, can address 220 = 1,048,576 or 1 MB of different memory locations. Thus the memory space of 8086 can be thought of as consisting of 1,048,576 bytes or 524,288 words. The memory map of 8086 is shown in Figure where the whole memory space starting from 00000 H to FFFFF H is divided into 16 blocks—each one consisting of 64KB.
1 MB memory of 8086 is partitioned into 16 segments—each segment is 64 KB in length. Out of these 16 segments, only 4 segments can be active at any given instant of time— these are the code segment, stack segment, data segment, and extra segment. The four memory segments that the CPU works with at any time are called currently active segments. Corresponding to these four segments, the registers used are Code Segment Register (CS), Data Segment Register (DS), Stack Segment Register (SS), and Extra Segment Register (ES) respectively. Each of these four registers is 16-bits wide and user accessible—i.e., their content can is changed by software.
The code segment contains the instruction codes of a program, while data, variables, and constants are held in the data segment. The stack segment is used to store interrupt and subroutine return addresses. The extra segment contains the destination of data for certain string instructions. Thus 64 KB are available for program storage (in CS) as well as for stack (in SS) while128 KB of space can be utilized for data storage (in DS and ES). One restriction on the base address (starting address) of a segment is that it must reside on a 16-byte address memory—examples being 00000 H, 00010 H, or 00020 H, etc.
Memory segmentation, as implemented for 8086, gives rise to the following advantages:
- Although the address bus is 20-bits in width, memory segmentation allows for work with registers having a g width of 16-bits only.
- It allows instruction code, data, s, tack, and portion of the program to be more than long by using more than one code, data, extra seg, men, and stack segment.
- In a time-shared multitasking environment when the program moves from one user’s program to another, the CPU will simply have to reload the segment register sisters with the segment starting addresses assigned to the current user’s program.
- User’s program (code) and data can be stored separately.
- Because the logical address range is from 0000 H to FFFF H, the same can be loaded at any place in the memory.