Introduction

  • In computer architecture, a processor register is a very fast computer memory used to speed up the execution of computer programs by providing quick access to commonly used values.
  • A register is a word of internal/CPU memory like the accumulator.
  • The most early machines used stack or accumulator type of architectures to manipulate data but these days all CPUs made are of GPR.
  • The number and the nature of registers is a key factor that differentiates among computers.

Definition

  • Register is the smallest (in size), costiest (in price) and fastest (in processing speed)memory, found in ALU/CU of computer, used to quickly accept, store, and transfer data and instructions that are being used immediately by the CPU/processor.

Features

  • Register is also called CPU or Processor or Internal memory.
  • Registers are typically addressed by mechanisms other than main memory.
  • They are volatile memory.
  • They are normally at the top of the memory hierarchy, and provide the fastest way to access data.
  • They store small amount of data, normally 1 to 2 byte per register but in some cases it may store 4-8 bytes or even more.
  • CPU can access registers faster than main memory.
  • Registers are easier for a compiler to use but tend to use a small number of registers because large numbers of registers are very difficult to use effectively. A general good number of registers is 32 in a general machine.
  • Registers usually consist of a small amount of fast storage, although some registers have specific hardware functions, and may be read-only or write-only.
  • Registers are typically addressed by mechanisms other than main memory.
  • A processor register may hold an instruction, a storage address, or any data (such as bit sequence or individual characters).
  • The computer needs processor registers for manipulating data and a register for holding a memory address.
  • One of the basic issues with register design is the number of general-purpose registers or data and address registers to be provided in a microprocessor. In general, it has been found that the optimum number of registers in a CPU is in the range 16 to 32. In case registers fall below the range then more memory reference per instruction on an average will be needed, as some of the intermediate results then have to be stored in the memory. On the other hand, if the number of registers goes above 32, then there is no appreciable reduction in memory references. The increased number of memory references results in slower execution of a program.
  • For addressing a register, depending on the number of addressable registers a few bit addresses is needed in an instruction. These address bits are definitely quite less in comparison to a memory address. For example, for addressing 256 registers we just need 8 bits, whereas, the common memory size of 1MB requires 20 address bits, i.e. a difference of 60%.
  • The instruction execution is performed in the CPU registers.
  • It is the temporary storage location in CPU for program execution.
  • Normally, the length of a register is dependent on its use. For example, a register, which is used to calculate address, must be long enough to hold the maximum possible addresses. In certain cases two consecutive registers may be used to hold data whose length is double of the register length.

Types of CPU/Processor Register

There are various type of Registers located inside Processor/CPU which are used for various purposes i.e. to store some data/addresses/instructions temporarily but in binary form. These are – 

(A) Basic Registers :

These registers are normally present in the computer and performs very important basic functions. These are –

  • Accumulator Register (AC):
    • This is the most frequently used register used to store data taken from main memory.
    • An accumulator is a specially designated register that supplies one instruction operand and receives the result. The instructions in such machines are normally one-address instructions.
    • This register is used to store data temporarily for computation by ALU.
    • AC is considered to contain one of the operands.
    • It is a general purpose processing register.
    • The result after computation by ALU is also stored back to this AC.
    • It is present in different numbers in different microprocessors.
    • Pros :
      • Implicit use of accumulator saves instruction bits.
      • Result is ready for immediate reuse, but has to be saved in memory if next computation does not use it right away.
      • More memory accesses required than stack
    • On an Accumulator machine C = A + B operation might be implemented as:-
LOAD A   (Load memory location A into accumulator)
ADD B    (Add memory location B to accumulator)
STORE C (Store accumulator value into memory location C)
    • On an Accumulator machine  A = B * C + D * E  operation might be implemented as:-
LOAD B (Load B in AC)
MULT C (Multiply AC with C in AC)
STORE T (Store B×C into Temporary T)
LOAD D (Load D in AC)
MULT E (Multiply E in AC)
ADD T (B×C + D×E)
STORE A (Store Result in A)
  • Memory Address Registers (MAR):
    • It holds the address of memory location from which data or instruction is to be accessed/fetched (read operation) or to which the data is to be stored (write operation).
    • Memory-address register (MAR) holds the address of next memory operation (load or store).
  • Memory Buffer Registers (MBR):
    • It is a register, which contains the data to be written in the memory (write operation) or it receives the data from the memory (read operation).
    • Memory-buffer register (MBR) holds the content of memory operation (load or store).
  • Program Counter (PC):
    • It is a register that contains the memory address of the next instruction to be executed/ fetched. PC points to the address of the next instruction to be fetched from the main memory when the previous instruction has been successfully completed.
    • It keeps track of the instruction that is to be executed next, that is, after the execution of an on-going instruction.
    • Program Counter (PC) is used to keep the track of execution of the program.
    • Program Counter (PC) also functions to count the number of instructions.
  • Instruction Register (IR):
    • A special registers that holds the instruction(s) currently being executed.
    • The instruction read from memory is placed in the Instruction register (IR) which is currently been executed.

(B) From a user’s point of view the register set can be classified under two basic categories-

(a) User/Programmer Visible Registers :

    • These registers are used to store temporary data items and other user accessible information useful for machine or assembly language programmers.
    • In another words, these registers can be used by machine or assembly language programmers to minimize the references to main memory.
    • These registers can be accessed using machine language.
    • These registers are –
      • General Purpose Registers
      • Segment Registers
      • Data Registers
      • Address Registers
      • General Purpose Register (GPR):
        • The general-purpose registers as the name suggests, is the collection of different type of registers which  can be used for various functions. For example, they may contain operands or can be used for calculation of address of operand etc.
        • This registers can be used for anything either holding operands for operations or temporary intermediate values.
        • The dominant architectures are IBM 370, PDP-11 and all Reduced Instant Set Computer (RISC) machines etc. possess this register.
        • This register can be used to store variables as it reduces memory traffic and speeds up execution.
        • It also improves code density.
        • Memory access can be minimized (registers can hold lots of intermediate values).
        • It has large instruction size than accumulator type machines.
        • Implementation is complicated, as compiler writer has to attempt to maximize register usage.
        • Instructions in GPR are of varying length from 1 byte to 6-8 bytes. This causes problems with the pre-fetching and pipelining of instructions.
      • Segment Register :
        • A segment register contains the addresses of instructions and data in memory which are used by the processor to access memory locations.
        • It indicates the starting address of a memory segment currently being used.
        • Segment Register may be of following types: –
          • Code segment (CS):
            • This is a 16-bit register containing address of 64 KB segment with processor instructions.
            • The processor uses CS segment for all accesses to instructions referenced by instruction pointer (IP) register.
            • Code segment holds the instruction codes of a program.
          • Stack segment (SS):
            • This is a 16-bit register containing address of 64KB segment with program stack.
            • By default, the processor assumes that all data referenced by the stack pointer (SP) and base pointer (BP) registers is located in the stack segment.
            • Stack segment holds the addresses and data of subroutines. It also holds the contents of registers and memory locations given in PUSH instruction.
            • SS register can be changed directly using POP instruction.
          • Data Segment(DS):
            • This is a 16-bit register containing address of 64KB segment with program data.
            • By default, the processor assumes that all data referenced by general registers (AX, BX, CX, and DX) and index register (SI, DI) is located in the data segment.
            • The data, variables and constants given in the program are held in the data segment of the memory.
          • Extra segment(ES):
            • Extra segment(ES) is a 16-bit register containing address of 64KB segment with program data.
            • By default, the processor assumes that all data referenced by general registers (AX, BX, CX, and DX) and index register (SI, DI) is located in the Extra segment.
            • Extra segment holds the destination addresses of some data of certain string instructions.
      • Data Register :
        • There are four 16-bit Data registers: AX (Accumulator Register), BX (Base Register), CX (Counter Register) and DX(Data Register). Each of these 16-bit data registers are further subdivided into 8-bit registers of Higher and Lower bit. 
        • This is a dedicated register i.e. the data registers are used only for storing intermediate results or data and not for operand address calculation.
        • Data Registers are of following types –
          • AX(Accumulator) :
            • It consists of two 8-bit registers AL and AH, which can be combined together and used as a 16-bit register AX.
            • Here, AL is the low-order byte of the word, and AH contains the high-order byte.
            • Accumulator can be used for I/O operations and string manipulation.
          • BX (Base register) :
            • It also consists of two 8-bit registers BL and BH, which can be combined together and used as a 16-bit register BX.
            • Here, BL is the low-order byte of the word, and BH contains the high-order byte.
            • BX register usually contains a offset value for data segment.
          • CX (Counter register) :
            • It also consists of two 8-bit registers CL and CH, which can be combined together and used as a 16-bit register CX.
            • Here, CL is the low-order byte of the word, and CH contains the high-order byte.
            • Count register can be used in Loop, shift/rotate instructions and as a counter in string manipulation.
          • DX (Data register) :
            • It also consists of two 8-bit registers DL and DH, which can be combined together and used as a 16-bit register DX.
            • Here, DL is the low-order byte of the word, and DH contains the high-order byte.
            • DX can be used as a port number in I/O operations.
            • In integer 32-bit multiply and divide instruction the DX register contains high-order word of the initial or resulting number.
      • Address/Pointer Register :
        • This is also a dedicated register i.e. the address registers are used only for storing address of the operand.
        • Some dedicated address registers are: –
        • Segment Pointer : Used to point out a segment of memory.
        • Index Register :
          • These are used for index addressing scheme.
          • This register may be –
          • Source Index (SI) Register :
            • This is a 16-bit register is used to hold the offset address for DS and ES in case of string manipulation instruction.
            • SI is used for indexed, based indexed and register indirect addressing, as well as a source data addresses in string manipulation instructions.
          • Destination Index (DI) Register :
            • This is a 16-bit register is used to hold the offset address for DS and ES in case of string manipulation instruction.
            • DI is used for indexed, based indexed and register indirect addressing, as well as a destination data addresses in string manipulation instructions.
        • Stack Pointer(SP) :
          • This register points to top of the stack when programmer visible stack addressing is used.
          • Stack Pointer (SP) is a 16-bit register is used to hold the offset address for stack segment.
        • Base Pointer(BP) :
          • It is a 16-bit register is used to hold the offset address for stack segment. 
          • BP register is usually used for based, based indexed or register indirect addressing.
          • The difference between SP and BP is that the SP is used internally to store the address in case of interrupt and the CALL instruction.
        • Instruction Pointer(IP) :
          • It is a 16-bit register.
          • The instruction pointer in the 8086 microprocessor acts as a program counter.
          • It indicates to the address of the next instruction to be executed.
          • It is used to hold the offset address for CS.

(b) Flag Registers :

    • A flag is a total 16-bit register in which 9 one bit flags are functional or existing whereas 7 one bit flags are unused. Among 9 one bit existing flags, 3 are Control flag Register and 6 are Status Flag Registers.
    • These registers are mainly used by control unit to control and coordinate the operations as well as to know/focus on the status of the process.
    • It exactly behaves like a flip-flop i.e. it changes states according to the result stored in the accumulator.
    • Flag Registers are categorised into –         

(i) Control Flag Registers :

      • These registers are mainly used by control unit to control and coordinate the operations
      • These registers cannot be used by the programmers but collectively are used to control the various CPU operations or the executions of the program.
      • These registers cannot be used in data manipulation work, however, the content of some of these registers can be used by the programmer.
      • Almost all the CPUs have a control register.
      • Control Flag Registers are – Direction Flag(DF), Interrupt Flag(IF) and Trap Flag(TF).
        • Direction Flag(DF):
          • This flag is used by string manipulation instructions.
          • If this flag bit is ‘0’, the string is processed beginning from the lowest address to the highest address i.e., auto-incrementing mode, otherwise flag bit ‘1’ represent the string is processed from the highest address towards the lowest address, i.e. auto-decrementing mode.
        • Interrupt flag(IF):
          • This flag is used for enabling or disabling interrupts operation with enable/disable flag.
          • If this flag is set, the maskable interrupts are recognized by the CPU. Otherwise they are ignored. Setting this bit enables maskable interrupts.
        • Trap Flag(TF):
          • If this flag is set, the processor enters the single step execution mode.
          • In other words, a trap interrupt is generated after execution of each instruction. The processor executes the current instruction and the control is transferred to the Trap interrupt service routine.

(ii) Status/Conditional Flag Registers :

      • The flag register is often known as Program Status Word (PSW). It contains condition code plus other status information. There can be several other status and control registers such as interrupt vector register in the machines using vectored interrupt, stack pointer if a stack is used to implement subroutine calls, etc.
      • Almost all the CPUs have a status register, a part of which may be programmer visible.
      • This register shows the processing status of a current going process and stores only single bit value(0/1) at a time to display the status.
      • The flag values are set/unset by the CPU hardware while performing an operation. For example, an addition operation may set the overflow flag or on a division by 0 the overflow flag can be set etc.
      • Processor status bits indicate the current status of the processor. Sometimes it is combined with the other processor status bits and is called the program status word (PSW).
      • It is a register which may be formed by condition codes is called condition code register.
      • Types of Status Flag Registers : Some of the commonly used flags or condition codes in such a register may be:-
        • Auxiliary flag(AF)
          • set if there was a carry from or borrow to bits 0-3 in the AL register.
        • Carry flag(CF)
          • This flag will be set, if a carry results from the addition of the highest order bits or borrow is taken on subtraction of highest order bit.
        • Parity flag(PF)
          • set if parity (the number of “1” bits) in the low-order byte of the result is even.
        • OverFlow Flag(OF)
          • This flag is used to indicate the condition of arithmetic overflow, if any during the operation.
        • Sign flag(SF)
          • This flag indicates whether the sign of previous arithmetic operation was positive (by storing 0) or negative (by storing 1).
        • Zero flag(ZF)
          • This flag bit will be set if the result of the last arithmetic operation was zero.

———————————————————————————

        • Equal flag
          • This flag will be set, if a logic comparison operation finds out that both of its operands are equal.
        • Supervisor flag
          • This flag is used in certain computers to determine whether the CPU is executing in supervisor or user mode. In case the CPU is in supervisor mode it will be allowed to execute certain privileged instructions.

Loading


0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.