Saturday, May 10, 2025

CPU Registers and Their types in details with examples.


CPU Registers and Their Types

What are CPU Registers?

Registers are small, high-speed storage locations inside the CPU used to hold data, addresses, and instructions temporarily while the processor is executing programs.

  • Faster than main memory (RAM)
  • Directly accessible by the CPU
  • Used to speed up processing

Types of CPU Registers

1. Accumulator (AC)

  • Stores intermediate results of arithmetic and logical operations.
  • Most operations use the accumulator by default.

Example:
For A = B + C, CPU loads B into AC, then adds C, and stores the result in AC.


2. Program Counter (PC)

  • Holds the address of the next instruction to be executed.
  • Automatically increments after fetching an instruction.

Example:
If the current instruction is at address 2000, PC = 2000. After fetching, PC = 2001.


3. Instruction Register (IR)

  • Stores the current instruction being executed.
  • Retrieved from memory using the address in the Program Counter.

Example:
If instruction at 2001 is ADD B, it will be loaded into the IR.


4. Memory Address Register (MAR)

  • Holds the memory address from which data will be fetched or to which data will be written.

Example:
If CPU needs data from address 3050, MAR = 3050.


5. Memory Buffer Register (MBR) / Memory Data Register (MDR)

  • Holds the data being transferred to or from memory.
  • Works along with MAR.

Example:

  • CPU wants to write value 42h at address 3050h
  • MAR = 3050h, MBR = 42h

6. General Purpose Registers (GPRs)

  • Temporarily hold data or intermediate results.
  • Examples: AX, BX, CX, DX in Intel 8086.

Example:
To compute (A + B) * C,

  • Store A and B in AX, BX → Add → result in AX
  • Store C in CX → Multiply AX and CX

7. Status Register / Flags Register

  • Stores flags indicating the status of operations:
    • Zero flag (Z) – set if result is 0
    • Carry flag (C) – set if there’s a carry/borrow
    • Sign flag (S) – set if result is negative
    • Overflow flag (O) – set on overflow

Example:
If you subtract 5 from 5 → result is 0 → Zero flag is set.


8. Stack Pointer (SP)

  • Points to the top of the stack in memory.
  • Stack is a LIFO (Last In First Out) memory area used for storing return addresses, local variables, etc.

Example:
During function calls, the return address is pushed to stack. SP updates accordingly.


9. Base Register and Index Register

  • Used for addressing modes in memory access.
  • Helps calculate effective addresses in array and structure access.


Summary Table

Register Purpose
AC Intermediate results
PC Next instruction address
IR Current instruction
MAR Address to access
MBR/MDR Data to/from memory
GPRs Temporary data
SP Stack management
Flags Operation status
Base/Index Complex addressing

No comments:

Post a Comment

mcq test

  ЁЯза Q71. If 1st January 2020 was Wednesday, then what day of the week was 1st January 2021? Choose the correct answer: --Selec...