Blog
Computer Architecture BSCS 4th Mid Past Paper 2016 – UOS Main Campus
University of Sargodha main campus (Department of Computer Science & Information Technology) Computer Architecture mid-term examination 2016 for BSCS 4th (30 marks, 90 minutes). Retyped from the original paper, with solved answers below.
Solved answers
Q1 – Cache mapping (10)
64-bit byte address, 64-byte lines → word/offset field = log₂64 = 6 bits. Addressable units = 2⁶⁴ bytes; blocks in main memory = 2⁶⁴/2⁶ = 2⁵⁸.
a) Direct mapped, tag = 40 bits: line field = 64 − 40 − 6 = 18 bits. Format: | Tag 40 | Line 18 | Word 6 |. Lines in cache = 2¹⁸ = 262,144 (cache size 2¹⁸ × 64 B = 16 MB). Tag size = 40 bits.
b) Fully associative: format | Tag 58 | Word 6 |. Addressable units 2⁶⁴, blocks 2⁵⁸, tag = 58 bits. The number of lines is not determined by the address format (any block can go in any line).
c) Four-way set associative, tag = 9 bits: set field = 64 − 9 − 6 = 49 bits. Format: | Tag 9 | Set 49 | Word 6 |. Lines per set = 4; sets = 2⁴⁹; lines in cache = 4 × 2⁴⁹ = 2⁵¹; tag = 9 bits; addressable units 2⁶⁴; blocks 2⁵⁸.
Q2 – Pipeline hazards in the 8-stage pipeline (10)
Structural hazards — two instructions need the same hardware in the same cycle. The split I-cache (IF1/IF2) and D-cache (MEM2) avoid a memory conflict; the register file must allow write in WB and read in ID in the same cycle.
Data hazards — an instruction needs a result that is not yet written back. Here the order is MEM1, MEM2, EX1, EX2: arithmetic results are ready only after EX2, logic results after EX1, and load data after MEM2. A dependent instruction in ID must wait (stall) or receive the value by forwarding (controlled from ID) from EX1/EX2/MEM2. Add/sub/shift results cause longer stalls (two-stage execute) than logic operations. RAW hazards are the main case; WAR/WAW cannot occur in this in-order pipeline.
Control hazards — branches. The branch is predicted in IF2, but the actual outcome is known only later, so a misprediction flushes the wrongly fetched instructions (several cycles of penalty). Dynamic branch prediction (Q3) and a branch target buffer reduce this penalty.
Q3 – 2-bit branch prediction (5)
Each branch has a 2-bit saturating counter with four states: 11 and 10 = predict taken, 01 and 00 = predict not taken. A taken branch moves the counter up (towards 11), a not-taken branch moves it down (towards 00). The prediction changes only after two consecutive mispredictions, so a loop branch that is mostly taken is mispredicted only once at the loop exit instead of twice (as with a 1-bit scheme).
Branch history table (BHT): a small table indexed by the low-order bits of the branch instruction’s address (PC), each entry holding the 2-bit state:
| Index (PC low bits) | 2-bit state | Prediction |
|---|---|---|
| 000 | 11 | Taken |
| 001 | 10 | Taken |
| 010 | 01 | Not taken |
| 011 | 00 | Not taken |
| … | … | … |
In IF2 the table is read to predict; when the branch resolves the entry is updated.
Q4 – Flynn’s classification (5)
- SISD (single instruction, single data): one control unit, one processing element, one data stream — a classic uniprocessor.
- SIMD (single instruction, multiple data): one control unit broadcasts the same instruction to many processing elements, each with its own data — vector processors, GPUs.
- MISD (multiple instruction, single data): several processing units apply different instructions to the same data stream — rare; fault-tolerant systems.
- MIMD (multiple instruction, multiple data): many processors, each with its own instructions and data — multicore CPUs, clusters (shared-memory or distributed-memory).
Draw each as boxes: CU (control unit) → instruction stream → PU (processing unit) ↔ MU (memory unit) via data stream, repeated as needed for each class.
