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.
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 answerHide 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:
| Feature | Description |
|---|---|
| Instruction Set | Large and complex set of instructions |
| Instruction Length | Variable length instructions |
| Addressing Modes | Many addressing modes supported |
| Memory Access | Instructions can directly access memory |
| Hardware | Complex hardware with microprogram control unit |
| Execution | Single 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:
- Incrementing of the control address register (sequential execution).
- Unconditional branch or conditional branch depending on status bit conditions.
- A mapping process from instruction bits to a control memory address.
- 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
| Feature | Conditional Branch | Unconditional Branch (BUN) |
|---|---|---|
| Condition | Depends on status bit | Always branches |
| Flexibility | More flexible | Fixed transfer |
| Use | Decision 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.
2080 · 5 marks
Differentiate between RISC and CISC architecture. [5]
2079 · 5 marks
Write short notes on (any two): a. CISC b. Overlapped register c. Pipelining hazards [5]
2075 · 5 marks
Differentiate between CISC and RISC architectures. [5]
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 answerHide 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 Type | Count |
|---|---|
| Three-Address | 6 |
| One-Address | 12 |
| Zero-Address | 14 |
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).
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 answerHide 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 Type | No. of Instructions |
|---|---|
| Three Address | 6 |
| One Address | 10 |
| Zero Address | 14 |
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.
2078 · 5 marks
What do you mean by instruction format? Explain with an example. [5]
Show solved answerHide 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) |
+-------+---+---+-------+---+---+-------+
| Field | Bits | Purpose |
|---|---|---|
| I (Indirect bit) | Bit 15 | Indicates direct (0) or indirect (1) addressing |
| Opcode | Bits 12 to 14 | Specifies the operation (3 bits = 8 possible operations) |
| Address | Bits 0 to 11 | Specifies 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.
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]
Data Transfer and manipulation
2079 · 5 marks
Explain the data transfer and manipulation instruction with example. [5]
2078 · 5 marks
Explain the data transfer instructions with example. [5]
2075.1 · 6 marks
Explain the data transfer instructions with example. [6]
Addressing Modes
2078 · 10 marks
Explain the various types of addressing modes and compare them algorithm, advantage and disadvantage.[10]
2077 · 5 marks
Explain the various addressing modes with example. [5]
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]
Make Unit 5 stick
Practice CSC213 with flashcards & quizzes