Sei sulla pagina 1di 3

The CPU Registers

The 8086 has 3 classes of registers. They are

• General Purpose Registers


• Segment Registers
• Special Registers

1. General Purpose Registers

The 8086 has 8 general-purpose registers, each of which is 16 bits wide. They are ax, bx,
cx, dx, si, di, bp and sp.

• ax (Accumulator) : Most arithmetic and logical computations use this register


• bx (Base Reg) : Normally used to store base addresses (later)
• cx (Count Reg) : Used for counting purposes, like number of iterations while looping,
number of characters in a string, etc.
• dx (Data Reg) : In my opinion, a true general purpose register.
• si (Source Index) : Used as a pointer to access memory indirectly
• di (Dest. Index) : Like the si register, this is also used for indirectly accessing the
memory
• bp (Base Pointer) : Like the bx register, this is also used to store base addresses.
Generally, this register is used to access local variables in a procedure.
• sp (Stack Pointer) : A very important register. Maintains the program stack, and so
should be used carefully.

In addition to the 16-bit registers, the 8086 also provides for 8-bit registers. These are ah, al,
bh, bl, ch, cl, dh, dl. These are not independent registers, but refer to the higher
and lower bytes of the ax, bx, cx and dx registers. The figure above will give a clear
picture of the relationship. Note that changing the value of ah modifies ax and vice versa.

2. Segment Registers

The 8086 has 4 special segment registers, viz. cs, ds, es and ss. These are 16-bit
registers and deal with selecting blocks (segments) of the memory.

• The cs (Code Segment) register points at the segment containing the currently
executing machine instructions. Since you can change the value of the cs register, you
can switch to a new code segment when you want to execute the code located there.
• The ds (Data Segment) register generally points at global variables for the program.
You can change the value of the ds register to access additional data in other segments.
• The es (Extra Segment) register is an extra segment register. 8086 programs often use
this segment register to gain access to segments when it is difficult or impossible to
modify the other segment registers.
• The ss (Stack Segment) register points at the segment containing the 8086 stack. The
stack is where the 8086 stores important machine state information, subroutine return
addresses, procedure parameters, and local variables. In general, you do not modify the
stack segment register because too many things in the system depend upon it.

3. Special Purpose Registers

There are two special purpose registers on the 8086, i.e. the instruction pointer (ip) and the flag
register. The ip is sometimes referred to as the pc (program counter). These registers cannot
be accessed directly, rather, they are modified by the cpu during execution.

The ip contains the address of the instruction being executed currently. This address is the
offset within the code segment, specified by the cs register.

The flag register (shown in the figure above) is a collection of 1-bit values that hold information
regarding the state of the system. Though it is a 16-bit register, only 9 of those bits are used. For
most practical purposes, only 4 flags are used: zero, carry, sign and overflow.

Segmentation

The 8086 is a 16-bit processor, with 16-bit registers and hence the address space which can be
accessed is 216 bits (i.e. 64 kilobytes). But with the clever use of segmentation, the address space
can be expanded to 1 Megabyte. Though 1 Megabyte seems very small in today's context, in
those days, it was a lot of memory (especially since the cost of making physical memory was
exhorbitant).

Before we start with segmentation, let us look at the way in which the address computation is
done in the 8086:

To provide flexible addressing capabilities, a data address may be formed by adding together a
combination of BX or BP contents, SI or DI contents and a displacement. (This we will see in
detail, when we cover addressing modes). The result of such a computation is called the offset or
the effective address (EA). The final address is determined by the EA and the appropriate data
segment (DS), extra segment (ES) or stack segment (SS) register.

Segmentation provides a powerful mechanism to manage memory. Programmers tend to partition


their program into logically independent modules. With segmentation, this logical partitioning can
be extended to keep these modules in physically independent sections (called segments).
Segmentation also allows two programs to share memory.

The effective address is a 16-bit value. However, to address 1 MB, there are 20 bits in the
physical address. Where do these extra 4 bits come from? They are obtained from the segment
register (to which the EA is added). The addition is carried out by appending four 0 bits to the
value of the segment register, before adding, thereby producing a 20-bit result. This is shown in
the figure below.

Therefore, an address on the 8086 is written as segment:offset. The size of the offset (16-bits)
limits the size of each segment to 64K. The number of segments is also limited to 65,536
segments per program, but this is not a practical limitation, since there are typically only about a
dozen segments in a program.

The use of segmentation typically divides the memory into overlapping segments, with each
segment being 64K bytes long and beginning at a 16-byte boundary. Summarizing
segmentation, the advantages are:

• Allows memory capacity to be 1 MB, though the addresses associated with each
instruction is only 16 bits.
• Allows the instruction, data or stack segment of a program to be more that 64K, by using
multiple code segments (or data/stack segments).
• Facilitate the use of separate memory areas for a program, its data, its stack, etc.

One of the reasons why segmentation is not a very popular concept among programmers is that it
is very difficult to access more than 256K of memory at once. This limitation is because there are
only segment registers. Accessing more than 256K requires quite a bit of bookkeeping.

Potrebbero piacerti anche