Data storage in Intel 8086

Memory banking is a technique used in microprocessors to manage memory access efficiently, especially when the width of the processor address bus is insufficient to address the entire memory space directly. In the case of the Intel 8086, memory banking is not implemented in hardware, but the segmented memory model used by the 8086 can be regarded as a form of memory banking. Below is a detailed explanation of how memory banking works in the context of the 8086:

Segmented memory model

The Intel 8086 processor uses a segmented memory model to address 1 MB (220 = 1,048,576 bytes) of memory with its 20-bit address bus. However, the registers of the 8086 processor are only 16 bits wide, so it cannot address the entire memory space directly. To overcome this limitation, the 8086 processor divides memory into segments, each of which is 64 KB in size.

How segmented memory works

Segment registers


The 8086 has four 16-bit segment registers:

CS (code segment): points to the segment containing the program code.

DS (data segment): points to the segment containing the data.

SS (stack segment): points to the segment containing the stack.

ES (extra segment): used for storing additional data.

Offset


A 16-bit offset within the segment is used to access a particular memory cell.

Physical address calculation


The physical address is calculated by the formula:

Physical address = (segment register << 4) + offset

The segment register is shifted left by 4 bits (which is equivalent to multiplying by 16), and then the offset is added to it to obtain the 20-bit physical address.

Analogy with memory banks

The segmented memory model can be regarded as a form of memory banks:

Each segment acts as a "bank" of memory.

The segment register selects the active bank.

The offset determines the location within the selected bank.

For example:

If the DS register (data segment) contains the value 1000h, it points to the segment that starts at physical address 10000h.

An offset of 0020h within this segment will result in the physical address:

Physical address = (1000h << 4) + 0020h = 10000h + 0020h = 10020h

Advantages of segmented memory (memory banking)

Larger address space: the 8086 can address up to 1 MB of memory using 16-bit segment registers and offsets.

Efficient memory management: segments let programs organise memory into logical blocks (for example, code, data, stack).

Flexibility: programs can switch between segments by changing the segment registers.

Disadvantages of segmented memory

Complex addressing: programmers have to manage segment registers and offsets, which can lead to errors.

Overlapping segments: segments can overlap, which leads to potential conflicts or loss of memory.

Overhead: calculating physical addresses incurs a small cost.

Example of memory banking in the 8086

Consider the following example:

Segment register (DS): 2000h

Offset: 0030h

The physical address is calculated as follows:

Physical address = (2000h << 4) + 0030h
= 20000h + 0030h
= 20030h

Segment 2000h acts as a "bank", and offset 0030h determines the location within that bank.

Comparison with true memory banking

In true memory banking:

Memory is divided into banks of a fixed size (for example, 64 KB each).

A bank select register is used to switch between banks.

The processor accesses memory within the selected bank using an offset.

In the 8086:

The segment registers act as bank select facilities.

The offset determines the location within the selected segment (bank).

Practical implications

Program development: programmers must manage segment registers carefully to avoid errors and ensure correct memory access.

Memory fragmentation: overlapping segments can lead to inefficient use of memory.

Compatibility: the segmented memory model influenced the design of later x86 processors, which retained backward compatibility with the 8086.

Summary

The Intel 8086 processor uses a segmented memory model to address 1 MB of memory with 16-bit segment registers and offsets. This model can be regarded as a kind of memory banks, where each segment acts as a "bank" of memory. Although this approach allows the 8086 processor to address a larger address space, it also complicates programming and memory management. The segmented memory model laid the foundation of the x86 architecture and influenced the design of modern processors.