Computer Architecture: Registers, Buses, Cache, RISC vs CISC

Computer architecture describes how the CPU, memory and input/output units are designed and connected, and how an instruction actually gets carried out. Lecturer, IT officer and programmer papers, and the computer part of ICS and ECAT, ask about registers, the three system buses, the instruction cycle, RISC and CISC, cache levels and addressing modes, and often set short calculations such as how much memory an address bus can reach. This lesson explains each idea and works through the standard calculations.

Asked in: PPSC, FPSC, NTS, ETEA, KPPSC, SSC, IBPS and ICS/ECAT computer

The CPU and its registers

The central processing unit has three main parts: the arithmetic logic unit (ALU), which does arithmetic and comparisons; the control unit (CU), which decodes instructions and sends control signals to every other part; and a small set of registers, the fastest storage in the computer, built inside the CPU itself.

The program counter (PC) holds the address of the next instruction to fetch. The memory address register (MAR) holds the address of the memory location about to be read or written, and the memory data register (MDR, also called the memory buffer register or MBR) holds the data travelling to or from that location. The instruction register (IR) holds the instruction currently being decoded and executed.

The accumulator (AC) is a general-purpose register that holds one operand and receives the result of ALU operations in simple machines. The status or flag register records facts about the last result, such as whether it was zero, negative or produced a carry or overflow, which conditional jumps then test. The stack pointer (SP) holds the address of the top of the stack in memory.

The system bus: address, data and control

The CPU, memory and I/O devices are connected by the system bus, a set of parallel lines divided into three groups. The address bus carries the address of the memory location or I/O port the CPU wants; it is unidirectional, running from the CPU outwards. The data bus carries the actual data and is bidirectional, because data both enters and leaves the CPU. The control bus carries timing and command signals such as memory read, memory write, interrupt request and the clock.

The width of the address bus decides how many different locations can be addressed: n address lines give 2ⁿ addresses. In a byte-addressable memory each address names one byte, so a 16-bit address bus reaches 2¹⁶ = 65,536 bytes = 64 KB, a 20-bit bus reaches 1 MB, and a 32-bit bus reaches 4 GB. The width of the data bus decides how many bits move in one transfer; a 64-bit data bus moves 8 bytes at a time.

Working backwards, the number of address lines needed for a memory of N locations is log₂ N. A memory described as 4K × 8 has 4096 locations of 8 bits each, so it needs 12 address lines and 8 data lines.

The instruction cycle

The CPU runs every program by repeating the instruction cycle, also called the fetch-decode-execute cycle. In the fetch step the address in the PC is copied to the MAR, the memory returns the instruction through the MDR, the instruction is copied into the IR, and the PC is increased to point to the next instruction.

In the decode step the control unit works out what the instruction means: which operation to perform and where its operands are. In the execute step the operation is carried out, for example by the ALU, and the result is stored in a register or written back to memory. If the instruction is a jump, executing it simply loads a new address into the PC.

At the end of each cycle the CPU checks whether any device has raised an interrupt. If so, it saves its current state and runs the interrupt service routine before continuing with the program.

RISC, CISC, von Neumann and Harvard

A CISC (complex instruction set computer) design offers a large number of powerful instructions of variable length, many addressing modes and instructions that can work directly on memory; one instruction may take several clock cycles. The x86 family used in most desktop and laptop PCs follows the CISC approach.

A RISC (reduced instruction set computer) design uses a small set of simple instructions of fixed length, many general-purpose registers and a load/store approach, in which only load and store instructions touch memory. Simple uniform instructions are easy to pipeline, aiming at about one instruction per clock cycle. ARM processors, found in most smartphones, are RISC designs.

In the von Neumann (stored-program) architecture, instructions and data share one memory and one bus, so they cannot be fetched at the same moment; this limit is called the von Neumann bottleneck. The Harvard architecture uses separate memories and buses for instructions and data, so both can be fetched together; it is common in microcontrollers and digital signal processors.

Memory hierarchy and cache

Faster memory costs more per byte, so a computer uses a hierarchy: registers, then cache, then main memory (RAM), then secondary storage such as SSDs and hard disks. Moving down the hierarchy, capacity grows while speed and cost per byte fall.

Cache is a small, fast memory, normally SRAM, that keeps copies of recently used data and instructions close to the CPU. Level 1 (L1) cache is the smallest and fastest and sits inside each core, often split into separate instruction and data caches. L2 is larger and somewhat slower, and L3 is larger still and is usually shared by all the cores.

When the CPU finds what it needs in the cache, it is a hit; otherwise it is a miss and the data must come from main memory. Hit ratio = hits ÷ total accesses. Cache works because programs show locality of reference: they tend to reuse recently used items (temporal locality) and items stored near them (spatial locality).

Addressing modes, clock speed and pipelining

An addressing mode tells the CPU where to find an operand. In immediate addressing the operand value itself is part of the instruction. In direct addressing the instruction holds the memory address of the operand. In indirect addressing the instruction holds an address whose memory location contains the address of the operand. In register addressing the operand is in a register, and in indexed addressing an index register is added to a base address, which suits arrays.

The clock sends regular pulses that keep the CPU’s operations in step. Clock speed is measured in hertz; 1 GHz is 10⁹ cycles per second, so the time of one cycle is 1 ÷ clock rate, and a 2 GHz clock has a cycle time of 0.5 ns. CPU time for a program = number of instructions × cycles per instruction (CPI) ÷ clock rate. Clock speed alone does not decide performance, because CPI, the number of cores and cache size also matter.

Pipelining overlaps the stages of different instructions, like an assembly line. With k stages of one cycle each and n instructions, an ideal pipeline needs k + (n − 1) cycles instead of k × n. A multi-core processor goes further by placing several complete processing cores on one chip.

Solved examples

  1. A processor has a 16-bit address bus and byte-addressable memory. What is the largest memory it can address directly? How much could it address if the bus were widened to 32 bits?
    1. n address lines give 2ⁿ different addresses, and each address names one byte.
    2. 2¹⁶ = 65,536 bytes, and 65,536 ÷ 1024 = 64 KB.
    3. For 32 lines: 2³² = 4,294,967,296 bytes = 4 × 1024³ bytes = 4 GB.
    Answer: 64 KB with 16 lines; 4 GB with 32 lines
  2. How many address lines are needed for a byte-addressable memory of 512 KB? How many address and data lines does an 8K × 16 memory chip need?
    1. 512 KB = 512 × 1024 = 2⁹ × 2¹⁰ = 2¹⁹ bytes, so 19 address lines are needed.
    2. 8K × 16 means 8 × 1024 = 2¹³ locations, each 16 bits wide.
    3. The chip therefore needs 13 address lines and 16 data lines.
    Answer: 19 lines; 13 address lines and 16 data lines
  3. Ayesha’s laptop CPU runs at 3.2 GHz. What is its clock cycle time, and how long does an instruction that needs 4 clock cycles take?
    1. Cycle time = 1 ÷ clock rate = 1 ÷ (3.2 × 10⁹) seconds.
    2. That is 0.3125 × 10⁻⁹ s = 0.3125 ns.
    3. Four cycles take 4 × 0.3125 = 1.25 ns.
    Answer: 0.3125 ns per cycle; 1.25 ns for the instruction
  4. A 5-stage pipeline, with each stage taking one clock cycle, runs 12 instructions. How many cycles are needed with and without pipelining, and what is the speed-up?
    1. Without pipelining every instruction passes through all 5 stages alone: 5 × 12 = 60 cycles.
    2. With an ideal pipeline the first instruction finishes after 5 cycles and one more finishes every cycle after that: 5 + (12 − 1) = 16 cycles.
    3. Speed-up = 60 ÷ 16 = 3.75.
    Answer: 60 cycles without, 16 cycles with pipelining; speed-up 3.75
  5. In a test run, 95% of a program’s memory accesses are cache hits. Assume a hit costs 2 ns and a miss costs 80 ns in total. What is the average access time?
    1. The miss ratio is 1 − 0.95 = 0.05.
    2. Average time = 0.95 × 2 + 0.05 × 80 = 1.9 + 4 = 5.9 ns.
    3. Even a 5% miss rate more than doubles the hit time, which is why a high hit ratio matters.
    Answer: 5.9 ns
  6. Hamza traces how the CPU fetches an instruction stored at address 300. List the registers it passes through and the value of the PC afterwards, assuming each instruction occupies one address.
    1. The PC holds 300, and this address is copied to the MAR.
    2. A memory read signal goes out on the control bus; the instruction at 300 comes back on the data bus into the MDR.
    3. The instruction is copied from the MDR into the IR for the control unit to decode.
    4. The PC is increased to 301, ready for the next fetch.
    Answer: PC → MAR → memory → MDR → IR; the PC then holds 301

Exam shortcuts

Common mistakes

Practice MCQs

  1. Which part of the system bus carries addresses in one direction only, from the CPU to memory and I/O?
    A) Control bus
    B) USB bus
    C) Address bus
    D) Data bus
    Answer: C) Address bus — The address bus carries the location the CPU wants, and only the CPU places addresses on it, so it is one-way. The data bus is two-way, the control bus carries signals such as read and write, and USB is an external peripheral connection, not part of the system bus.
  2. Which register holds the instruction that the control unit is currently decoding and executing?
    A) Program counter (PC)
    B) Accumulator
    C) Memory address register (MAR)
    D) Instruction register (IR)
    Answer: D) Instruction register (IR) — The IR receives each fetched instruction and holds it while it is decoded and executed. The PC holds the address of the next instruction, the MAR holds an address to be accessed, and the accumulator holds data and ALU results.
  3. Which register holds the data that has just been read from memory or is about to be written to it?
    A) Instruction register (IR)
    B) Memory address register (MAR)
    C) Flag register
    D) Memory data register (MDR)
    Answer: D) Memory data register (MDR) — The MDR, also called the MBR, is the buffer for the data moving between the CPU and memory. The MAR holds only the address, the IR holds the current instruction, and the flag register records conditions such as zero and carry.
  4. Which level of cache is the smallest and fastest and is normally built inside each CPU core?
    A) L2 cache
    B) L1 cache
    C) Main memory
    D) L3 cache
    Answer: B) L1 cache — L1 sits closest to the execution units and is the smallest and fastest cache. L2 is larger and slower, L3 is larger again and usually shared between cores, and main memory is not cache at all.
  5. A processor has a 16-bit address bus and its memory is byte-addressable. What is the maximum memory it can address?
    A) 64 KB
    B) 32 KB
    C) 1 MB
    D) 16 KB
    Answer: A) 64 KB — 16 address lines give 2¹⁶ = 65,536 addresses, one byte each, which is 64 KB. 16 KB and 32 KB correspond to 14 and 15 lines, and 1 MB needs 20 lines.
  6. Which feature is characteristic of a RISC processor?
    A) Many addressing modes for each instruction
    B) A large number of memory-to-memory instructions
    C) A small set of simple, fixed-length instructions
    D) Many complex instructions of varying length
    Answer: C) A small set of simple, fixed-length instructions — RISC designs keep instructions few, simple and the same length so they can be pipelined efficiently, and only load and store touch memory. Complex variable-length instructions, memory-to-memory operations and many addressing modes are features of CISC.
  7. What is the clock cycle time of a processor running at 2.5 GHz?
    A) 4 ns
    B) 0.4 ns
    C) 0.25 ns
    D) 2.5 ns
    Answer: B) 0.4 ns — Cycle time = 1 ÷ (2.5 × 10⁹) s = 0.4 × 10⁻⁹ s = 0.4 ns. 2.5 ns simply repeats the frequency figure, 4 ns is ten times too large, and 0.25 ns would be the cycle time of a 4 GHz clock.
  8. Signals such as memory read, memory write and interrupt request travel on which bus?
    A) Address bus
    B) Control bus
    C) Data bus
    D) Expansion slot
    Answer: B) Control bus — The control bus carries the command and timing signals that coordinate the other parts. The address bus carries locations, the data bus carries the values being moved, and an expansion slot is a connector for adding cards rather than a bus line group.
  9. In the instruction ADD R1, 25 the number 25 is itself the value to be added. Which addressing mode is this?
    A) Immediate addressing
    B) Direct addressing
    C) Indirect addressing
    D) Indexed addressing
    Answer: A) Immediate addressing — When the operand value is part of the instruction, the mode is immediate. Direct addressing would treat 25 as the memory address of the value, indirect would treat it as the address of the address, and indexed would add an index register to a base address.
  10. An instruction contains the address of a memory location, and that location holds the address of the actual operand. Which addressing mode is used?
    A) Immediate addressing
    B) Register addressing
    C) Indirect addressing
    D) Direct addressing
    Answer: C) Indirect addressing — Going through one address to reach another address is indirect addressing, which needs an extra memory access. Direct addressing gives the operand’s own address, immediate gives the operand itself, and register addressing finds the operand in a CPU register.
  11. Which architecture uses separate memories and buses for instructions and data, so that both can be fetched at the same time?
    A) Von Neumann architecture
    B) Client-server architecture
    C) Harvard architecture
    D) CISC architecture
    Answer: C) Harvard architecture — The Harvard architecture keeps program and data apart, removing the shared-bus bottleneck; it is common in microcontrollers and DSPs. The von Neumann design shares one memory, CISC describes the instruction set rather than memory layout, and client-server describes networks.
  12. How many address lines are needed for a 4K × 8 memory chip?
    A) 12
    B) 8
    C) 4
    D) 32
    Answer: A) 12 — 4K = 4096 = 2¹² locations, so 12 address lines are needed. 8 is the number of data lines (the word width), 4 is the K-figure taken literally, and 32 would address 4 G locations.
  13. Out of 1,200 memory accesses made by a program, 1,080 are found in the cache. What is the hit ratio?
    A) 80%
    B) 88%
    C) 10%
    D) 90%
    Answer: D) 90% — Hit ratio = hits ÷ total = 1,080 ÷ 1,200 = 0.9, or 90%. 10% is the miss ratio, and 80% and 88% come from arithmetic slips.
  14. A 4-stage pipeline, each stage taking one clock cycle, executes 20 instructions. Ignoring stalls, how many cycles are needed?
    A) 24
    B) 23
    C) 20
    D) 80
    Answer: B) 23 — An ideal pipeline needs k + n − 1 = 4 + 20 − 1 = 23 cycles. 80 is the non-pipelined count 4 × 20, 24 adds the stages without subtracting 1, and 20 ignores the cycles needed to fill the pipeline.
  15. A program executes 8 million instructions with an average of 1.5 clock cycles per instruction on a 2 GHz processor. What is its CPU time?
    A) 6 ms
    B) 24 ms
    C) 4 ms
    D) 2.67 ms
    Answer: A) 6 ms — CPU time = 8 × 10⁶ × 1.5 ÷ (2 × 10⁹) = 12 × 10⁶ ÷ (2 × 10⁹) s = 0.006 s = 6 ms. 4 ms ignores the CPI, 2.67 ms divides by the CPI instead of multiplying, and 24 ms multiplies by the clock figure instead of dividing.

Questions

What is the difference between computer architecture and computer organisation?

Architecture is what the programmer sees: the instruction set, data types, addressing modes and registers. Organisation is how that design is built in hardware: the buses, control signals, memory technology and pipelines.

Why is the data bus bidirectional but the address bus not?

Data must flow into the CPU when reading and out of it when writing, so the data bus works both ways. Addresses are produced only by the CPU (or a DMA controller acting for it), so they travel outwards only.

Does a 64-bit processor mean it can use 2⁶⁴ bytes of memory?

Not in practice. The 64 bits describe the register and data width; the number of physical address lines actually built in is smaller, so the real memory limit is set by the address bus and the chipset.

Is RISC better than CISC?

Neither is simply better. RISC aims for simple instructions that pipeline well and save power, while CISC packs more work into each instruction. Modern x86 chips even translate CISC instructions into RISC-like internal operations.