Registers

Definition

Register is a quickly accessible location available to a computer’s CPU, which usually consists of a small amount of fast storage.

Size of Registers

  • 8-bit register
  • 32-bit register
  • 64-bit register

Types of Registers

User-accessible Registers

It can be read or written by machine instructions.

It has the following types:

  • Data Registers: A special data register, known as the accumulator, is used implicitly for many operations.
  • Address Registers
  • General-purpose Registers (GPRs): It can store both data and addresses.
  • Status Register (Flag Register / Condition Code Register (CCR) / FLAGS Register / Program Status Word (PSW) Register): It is a collection of status flag bits for a processor.
  • Floating-point Registers (FPRs): They store floating point numbers in many architectures.
  • Constant Registers: They hold read-only values such as zero, one, or π\pi.
  • Vector Registers: They hold data for vector processing done by Single Instruction, Multiple Data (SIMD) instructions.
  • Special-purpose Registers (SPRs):
    • They hold program states.
    • Include the program counter (instruction pointer), and the status register.
    • Program counter and status register might be combined in a program status word (PSW) register.
  • Model-specific Registers (Machine-specific Registers): They store data and settings related to the processor itself.

Internal Registers

It can not be accessible by instructions, and it is used internally for processor operations.

An instruction register holds the instruction currently being executed.

There are some registers related to fetching information from RAM:

  • Memory Buffer Register (MBR)
  • Memory Data Register (MDR)
  • Memory Address Register (MAR)

Register 8086

The 8086 Register
Main Register (Data Registers)
AH AL AX (Primary Accumulator)
BH BL BX (Base Accumulator)
CH CL CX (Counter Accumulator)
DH DL DX (Accumulator, Other Function)
Index or Pointer Register
SI Source Index
DI Destination Index
BP Base Pointer
SP Stack Pointer
Flag Register
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 Bit Position
- - - - O D I T S Z - A - P - C Flags (CAPSZO + IDT)
Segment Registers
CS Code Segment
DS Data Segment
SS Stack Segment
ES Extra Segment
Instruction Pointer
IP Instruction Pointer

FLAGS Register

It contains the current state of the processor.

Sizes

  • FLAGS Register: 16 bits
  • EFLAGS Register: 32 bits
  • RFLAGS Register: 64 bits

Types of FLAGS

Status Flags

It determines the kind of the result of arithmetic execution.

The Carry Flag (CF)

It determines whether there is a carry from the MSB on addition or there is a borrow into the MSB on subtraction.

The Parity Flag (PF)

It determines whether the result is even.

The Auxiliary Flag (AF)

It determines whether there is a carry from bit 3 on addition or a borrow into the bit 3 on subtraction.

The Zero Flag (ZF)

It determines whether the result is zero.

The Sign Flag (SF)

It determines whether the MSB is 11.

The Overflow Flag (OF)

It determines whether signed overflow occurred.

Determine CF and OF

Suppose both numbers have 8 bits.

On the addition:

For example:

1111  1111+0000  0001=1  0000  00001111 \; 1111 + 0000 \; 0001 = 1 \; 0000 \; 0000 will cause a carry on the most left bit, then the CF will be turned on, but the OF will not be turned on.

The change of OF will happen only when both numbers have the same signs, which is potential to be signed overflowed.

For example:

1000  0000+1000  0000=1  0000  00001000 \; 0000 + 1000 \; 0000 = 1 \; 0000 \; 0000. The sign changed to 00, meaning the overflow occurs, so the OF will be turned on as well as CF.

On the subtraction:

There are two operands: minuend and subtrahend.

The subtrahend can be transformed to its two’s complement at first, and then to perform the addition.

When performing the addition, we can get the CF and OF. And the correct CF and AF are the inverse of addition’s while the correct OF is the same as addition’s.

Control Flags

Control flags are used to enable or disable certain operations of microprocessor, which includes:

  • Directional Flag (D)
  • Interrupt Flag (I)
  • Trap Flag (T)
Directional Flag

It is used in string instructions to determine the direction of accessing string data.

If it is 11, then it means accessing string data from higher memory location towards lower one. Otherwise, it will access string data from lower memory location to higher one.

Interrupt Flag

It is used to tell the microprocessor whether to interrupt when accessing to this flag.

If this is set to 11, the microprocessor will interrupt at this bit, Otherwise, the microprocessor will ignore it.

System Flags

They are useful for operating system designer, security management, and for supporting multimedia applications.

Last updated on