5 Central Processing Unit

Computer Architecture · Unit 5 · 4 hrs

Central Processing Unit

Exam-focused notes for Central Processing Unit (Computer Architecture, CSC213): what the TU syllabus asks and how it has actually been tested, with 15 solved past questions from this unit.

Central Processing Unit in short

Having built one small hardwired machine and its microprogrammed alternative, this chapter widens the view to how CPUs in general are organized, addressed and instructed, and closes with the RISC-versus-CISC design debate that runs through the rest of the subject.

Central Processing Unit: notes

Major Components of CPU

The central processing unit (CPU) is the component that carries out a computer's data-processing operations, built from three cooperating parts: a register set, which holds intermediate data and addresses during instruction execution; the arithmetic logic unit (ALU), which performs the arithmetic and logic microoperations an instruction requires; and the control unit (CU), which sequences the transfer of information among the registers and directs the ALU's operation.

CPU Organization

CPUs are organized in one of three ways. An accumulator-based organization uses a single accumulator (AC) as the implicit source and destination of every ALU operation, giving the shortest instructions (opcode plus one address, since AC is always the other operand) and the cheapest hardware, at the cost of extra memory traffic when expressions grow complex. A general register organization provides several processor registers so that two- or three-address instructions can be used, trading more hardware for fewer memory references and higher speed. A stack organization replaces explicit addresses with an implicit top-of-stack reference, so most instructions need no address field at all.

Instruction Formats

An instruction is divided into fields: an opcode field, an address field (one or more), and, when addressing modes are supported, a mode field. Instructions are classified by how many address fields they carry: three-address ($ADD\ R_1,A,B$), two-address ($ADD\ R_1,B$, one register doubling as source and destination), one-address ($ADD\ B$, implicitly operating on AC), and zero-address ($ADD$, implicitly operating on the stack).

Worked example. Evaluating $Y=(A+B)\times(C-D)$ in each format:

Zero-address (stack)One-address (AC)Two-addressThree-address
PUSH ALOAD AMOV R1,AADD R1,A,B
PUSH BADD BADD R1,BSUB R2,C,D
ADDSTORE TMOV R2,CMUL Y,R1,R2
PUSH CLOAD CSUB R2,D
PUSH DSUB DMUL R2,R1
SUBMUL TMOV Y,R2
MULSTORE Y
POP Y

What this unit covers

  • Major Components of CPU
  • CPU Organization
  • Instruction Formats
  • Addressing Modes
  • Data Transfer and manipulation
  • Program Control
  • Subroutine Call and Return
  • Types of Interrupt
  • RISC vs CISC
  • Pros and Cons of RISC and CISC
  • Overlapped Register Windows

RISC vs CISC

2081 · 5 marks

Write short notes on: a) CISC b) Conditional branch [5]

Show solved answer

Short Notes: a) CISC b) Conditional Branch


a) CISC (Complex Instruction Set Computer)

CISC is a processor design philosophy where the CPU is capable of executing a large number of complex instructions, each of which can perform multiple low-level operations (such as memory access, arithmetic, and logic) in a single instruction.

Key Characteristics of CISC:

FeatureDescription
Instruction SetLarge and complex set of instructions
Instruction LengthVariable length instructions
Addressing ModesMany addressing modes supported
Memory AccessInstructions can directly access memory
HardwareComplex hardware with microprogram control unit
ExecutionSingle instruction may take multiple clock cycles

Key Points:

  • CISC emphasizes doing more work per instruction, reducing the number of instructions per program.
  • It uses microprogrammed control to implement complex instructions.
  • Examples: Intel x86, Intel 8086, VAX processors.
  • The compiler work is reduced since complex operations are handled directly by hardware.
  • CISC processors typically have a large control memory to store microinstructions for each complex instruction.

b) Conditional Branch

Conditional branch is a type of branching mechanism in which the transfer of control to a new address depends on the status (condition) of one or more status bits (flags) at the time of execution.

Definition:

Conditional branching is obtained by using part of a micro-instruction to select a specific status bit in order to determine its condition. The branch logic provides decision-making capabilities in the control unit.

How It Works:

  • A portion of the micro-instruction specifies which status bit to test (e.g., zero flag, carry flag, sign flag).
  • If the condition is TRUE -- the branch is taken and the program jumps to the specified address.
  • If the condition is FALSE -- execution continues sequentially (next instruction).

Block Diagram (Conceptual):

Control Memory
      |
      v
[Micro-instruction] --> [Branch Logic] <-- [Status Bits (flags)]
                               |
                    ---------------------
                    |                   |
              Condition TRUE      Condition FALSE
                    |                   |
             Branch Address      Next Sequential Address

Methods of Selecting Next Microinstruction Address:

The following methods are used:

  1. Incrementing of the control address register (sequential execution).
  2. Unconditional branch or conditional branch depending on status bit conditions.
  3. A mapping process from instruction bits to a control memory address.
  4. A facility for subroutine call and return.

Example:

  • In a basic computer, instructions like ISZ (Increment and Skip if Zero) use conditional branching:
    • After incrementing, if DR = 0, then PC is incremented by 1 (branch/skip).
    • Otherwise, execution continues normally.

Difference: Conditional vs Unconditional Branch

FeatureConditional BranchUnconditional Branch (BUN)
ConditionDepends on status bitAlways branches
FlexibilityMore flexibleFixed transfer
UseDecision making (if-else, loops)Simple jump

Significance:

Conditional branching is essential for implementing loops, if-else decisions, and program flow control in both high-level programs and microprogram control units.

Open this answer on its own page →

2080 · 5 marks

Differentiate between RISC and CISC architecture. [5]

RISC (Reduced Instruction Set Computer) and CISC (Complex Instruction Set Computer) are two fundamental approaches to processor design that differ in philosophy, instruction complexity, and implementation. --- Aspect CISC RISC --------- Emphasis Gives emphasis on hardware Gives emphasis on softwa...

Open this answer on its own page →

2079 · 5 marks

Write short notes on (any two): a. CISC b. Overlapped register c. Pipelining hazards [5]

--- CISC is a processor design philosophy that emphasizes hardware complexity to support a rich and varied instruction set. Feature CISC ------ Emphasis Hardware Instruction size Multiple sizes and formats Registers Fewer registers used Addressing modes More addressing modes Execution Multiple cl...

Open this answer on its own page →

2075 · 5 marks

Differentiate between CISC and RISC architectures. [5]

CISC (Complex Instruction Set Computer) and RISC (Reduced Instruction Set Computer) are two fundamental processor design philosophies. Their key differences are as follows: --- CISC RISC ------ Gives emphasis on hardware Gives emphasis on software Has multiple instruction sizes and formats Has in...

Open this answer on its own page →

2075.1 · 6 marks

Explain the CISC architecture with example. [6]

CISC (Complex Instruction Set Computer) is a processor architecture in which a single instruction can execute several low-level operations (such as a load from memory, an arithmetic operation, and a memory store) in one instruction cycle. The control unit in CISC is implemented using a microprogr...

Open this answer on its own page →

Instruction Formats

2080 · 5 marks

Write the program for following statement by using three, single, zero address instructions. $X = (A+BC-D)/(EF+G)$ [5]

Show solved answer

X = (A + BC - D) / (EF + G)

Using Three-Address, One-Address (Accumulator), and Zero-Address (Stack) instructions.

Given Data

  • Expression: $X = \dfrac{A + B \cdot C - D}{E \cdot F + G}$
  • Operands: $A, B, C, D, E, F, G$
  • Operations: multiply, add, subtract, divide

Three-Address Instructions

Format: OP dest, src1, src2 meaning dest = src1 OP src2

MUL  T1, B, C      ; T1 = B * C
ADD  T2, A, T1     ; T2 = A + B*C
SUB  T3, T2, D     ; T3 = A + B*C - D    (numerator)
MUL  T4, E, F      ; T4 = E * F
ADD  T5, T4, G     ; T5 = E*F + G        (denominator)
DIV  X,  T3, T5    ; X  = T3 / T5

Total: 6 instructions


One-Address Instructions (Accumulator based)

Format: OP M meaning AC = AC OP M

LOAD  B            ; AC = B
MUL   C            ; AC = B*C
ADD   A            ; AC = A + B*C
SUB   D            ; AC = A + B*C - D
STORE T1           ; T1 = numerator
LOAD  E            ; AC = E
MUL   F            ; AC = E*F
ADD   G            ; AC = E*F + G
STORE T2           ; T2 = denominator
LOAD  T1           ; AC = numerator
DIV   T2           ; AC = numerator / denominator
STORE X            ; X = result

Total: 12 instructions


Zero-Address Instructions (Stack based)

Format: PUSH/POP M for memory access; arithmetic ops act on top two stack elements.

PUSH  A            ; [A]
PUSH  B            ; [A, B]
PUSH  C            ; [A, B, C]
MUL                ; [A, B*C]
ADD                ; [A+B*C]
PUSH  D            ; [A+B*C, D]
SUB                ; [A+B*C-D]              (numerator)
PUSH  E            ; [num, E]
PUSH  F            ; [num, E, F]
MUL                ; [num, E*F]
PUSH  G            ; [num, E*F, G]
ADD                ; [num, E*F+G]           (denominator)
DIV                ; [num/den]
POP   X            ; X = result

Total: 14 instructions


Summary

Instruction TypeCount
Three-Address6
One-Address12
Zero-Address14

As the number of addresses per instruction decreases, more instructions are required, but each instruction becomes simpler and shorter.

All three programs evaluate the expression correctly while respecting operator precedence (multiplication before addition and subtraction, numerator and denominator computed before division).

Open this answer on its own page →

2079 · 5 marks

Write the program for the following statement using three, single, zero address instructions. $X = (AB+C-D) / (E+FG)$ [5]

Show solved answer

Given

Given data:

  • Expression: $X = (AB + C - D) / (E + FG)$
  • Required representations: three-address, one-address (single), zero-address instructions.

No numeric values are involved; this is a symbolic instruction-set problem.


Solution

1. Three-Address Instructions

Format: OP DEST, SRC1, SRC2

MUL R1, A, B       ; R1 = A * B
ADD R1, R1, C      ; R1 = A*B + C
SUB R1, R1, D      ; R1 = A*B + C - D
MUL R2, F, G       ; R2 = F * G
ADD R2, E, R2      ; R2 = E + F*G
DIV X,  R1, R2     ; X = (A*B + C - D) / (E + F*G)

Total: 6 instructions


2. One (Single) Address Instructions

Format uses the Accumulator (AC): OP M means $AC = AC ; \text{OP} ; M[M]$

LOAD  F        ; AC = F
MUL   G        ; AC = F*G
ADD   E        ; AC = E + F*G
STORE T        ; T = E + F*G
LOAD  A        ; AC = A
MUL   B        ; AC = A*B
ADD   C        ; AC = A*B + C
SUB   D        ; AC = A*B + C - D
DIV   T        ; AC = (A*B + C - D) / (E + F*G)
STORE X        ; X = result

Total: 10 instructions

Note: The denominator is computed first so that only one temporary (T) is needed and the numerator can remain in the accumulator for the final DIV. An alternative 12-instruction version computes both sub-expressions, stores both, then reloads, which works but uses two extra instructions. The 10-instruction form is the standard optimal solution.


3. Zero-Address Instructions (Stack-Based)

Operands are implicit on the stack. Uses PUSH / POP for memory access and arithmetic on top two elements.

Postfix (reverse Polish) of the expression: $$A,B,,C,+,D,-,E,F,G,,+,/$$

PUSH A         ; A
PUSH B         ; A, B
MUL            ; A*B
PUSH C         ; A*B, C
ADD            ; A*B+C
PUSH D         ; A*B+C, D
SUB            ; A*B+C-D
PUSH E         ; A*B+C-D, E
PUSH F         ; A*B+C-D, E, F
PUSH G         ; A*B+C-D, E, F, G
MUL            ; A*B+C-D, E, F*G
ADD            ; A*B+C-D, E+F*G
DIV            ; (A*B+C-D)/(E+F*G)
POP  X         ; X = result

Total: 14 instructions


Summary Table

Instruction TypeNo. of Instructions
Three Address6
One Address10
Zero Address14

Key Observation: As the number of addresses per instruction decreases, the number of instructions needed increases.

For the one-address form the optimal solution needs 10 instructions; a version that stores and reloads both operands needs 12. Both are logically correct, and 10 is the minimal standard form.

Open this answer on its own page →

2078 · 5 marks

What do you mean by instruction format? Explain with an example. [5]

Show solved answer

Instruction Format

Definition

An instruction format defines the layout or structure of a binary instruction stored in memory. It specifies how the bits of an instruction are divided into different fields, each carrying specific information needed by the CPU to execute that instruction.

The simplest way to organize a computer is to have a single processor register called the accumulator, and an instruction format with two parts:

  • First part (Opcode field): Specifies the operation to be performed (e.g., ADD, SUB, LOAD, STORE).
  • Second part (Address field): Specifies the memory address where the operand is located, i.e., tells the control unit where to find the operand in memory.

General Structure of an Instruction Format

+------------------+----------------------+
|   Opcode (bits)  |   Address (bits)     |
+------------------+----------------------+

Example: Basic Computer Instruction Format (16-bit)

In a basic computer, each instruction is 16 bits long, organized as follows:

Bit position:  15      14  13  12      11  10  9  ...  0
               +-------+---+---+-------+---+---+-------+
               |   I   | Opcode (3)    |  Address (12) |
               +-------+---+---+-------+---+---+-------+
FieldBitsPurpose
I (Indirect bit)Bit 15Indicates direct (0) or indirect (1) addressing
OpcodeBits 12 to 14Specifies the operation (3 bits = 8 possible operations)
AddressBits 0 to 11Specifies the memory address of the operand (12 bits = 4096 locations)

How It Works During Fetch and Decode

According to the fetch-decode cycle:

  • T0: AR <- PC (Address Register gets the Program Counter value)
  • T1: IR <- M[AR], PC <- PC + 1 (Instruction is fetched from memory into Instruction Register)
  • T2: Decode IR(12-14), AR <- IR(0-11), I <- IR(15) (Opcode bits 12-14 are decoded; address bits 0-11 are loaded into AR; indirect bit is noted)

Example Instruction

Suppose a 16-bit instruction is:

0  001  000000000101
^   ^        ^
I  Opcode   Address (5)
  • I = 0 → Direct addressing
  • Opcode = 001 → Could represent an ADD operation
  • Address = 5 → Operand is located at memory address 5

This means: "Add the value stored at memory location 5 to the accumulator directly."


Summary

Instruction format is essential because it tells the CPU what to do (opcode) and where to find the data (address). The design of the instruction format directly affects the number of operations supported and the size of addressable memory.

Open this answer on its own page →

2077 · 5 marks

Write codes using 3, 2 and 1 address instruction formats to perform the given operations. $X = A/B + C * D/C$ [5]

  • Expression to evaluate: $X = A/B + C \ast D / C$ - Required formats: 3-address, 2-address, 1-address instructions. $$X = (A/B) + ((C \ast D)/C)$$ Sub-operations: 1. $T1 = A/B$ 2. $T2 = C \ast D$ 3. $T3 = T2/C$ 4. $X = T1 + T3$ --- Format: OPCODE Dest, Src1, Src2 Instruction Operation ------ DIV...
Open this answer on its own page →

Data Transfer and manipulation

2079 · 5 marks

Explain the data transfer and manipulation instruction with example. [5]

Instructions in a computer can be broadly classified based on the operations they perform. Two fundamental categories are data transfer instructions and data manipulation instructions. --- Data transfer instructions move data from a source to a destination without performing any arithmetic or log...

Open this answer on its own page →

2078 · 5 marks

Explain the data transfer instructions with example. [5]

Data transfer instructions are a category of computer instructions used to move data between registers, memory, and I/O devices without performing any arithmetic or logical operation on the data. They form the most fundamental class of instructions in any instruction set. --- The basic computer s...

Open this answer on its own page →

2075.1 · 6 marks

Explain the data transfer instructions with example. [6]

Data transfer instructions are a category of computer instructions that move data between the CPU registers, memory, and I/O devices without performing any arithmetic or logical operation on the data. They form the most fundamental class of instructions in any instruction set. --- The following a...

Open this answer on its own page →

Addressing Modes

2078 · 10 marks

Explain the various types of addressing modes and compare them algorithm, advantage and disadvantage.[10]

The addressing mode specifies a rule for interpreting or modifying the address field of an instruction before the operand is actually referenced or executed. In other words, the way in which the operand of an instruction is specified is called an addressing mode. --- Algorithm / Working: - The op...

Open this answer on its own page →

2077 · 5 marks

Explain the various addressing modes with example. [5]

An addressing mode specifies how the operand (or the address of the operand) is determined from the instruction. Different addressing modes provide flexibility in accessing data stored in registers, memory, or within the instruction itself. --- - The operand is directly specified within the instr...

Open this answer on its own page →

Overlapped Register Windows

2075 · 10 marks

In the RISC architecture, what is meant by over lapping register window? Explain the relationship among register windows with over lapping register windows.[10]

RISC (Reduced Instruction Set Computer) architecture emphasizes simplicity and speed. One of its key features is the use of a large register file organized into overlapping register windows to handle procedure calls efficiently without the overhead of saving and restoring registers in memory. ---...

Open this answer on its own page →