Full marks 30. Q1 arithmetic, Q2 pipelining, Q3 cache β the standard skeleton. Try each part before revealing.
Q1 β Arithmetic CO3
1abig(a) Devise the multiplication algorithm to multiply two n-bit integers. Estimate its time and space complexity. [4]
Algorithm (sequential shift-add). Product β 0. Repeat n times:
for i = 1 to n:
if (Multiplier LSB == 1):
Product = Product + Multiplicand
shift Multiplicand LEFT by 1
shift Multiplier RIGHT by 1
Multiplying an n-bit by an m-bit number gives an (n+m)-bit product. Time complexity:n iterations, each an add + shifts β O(n) steps. Space complexity: registers for multiplicand, multiplier and a 2n-bit product β O(n).
2abig(a) Explain and exemplify a structural hazard, then discuss its solution. [4]
A structural hazard arises when two instructions in different stages need the same hardware resource in the same cycle. Example: with a single unified memory, in one cycle an early instruction does its data access (MEM) while a later one needs instruction fetch (IF) β both require the one memory. Solution: duplicate the resource β use a split cache (separate instruction and data memories). Real MIPS does this, eliminating the hazard.
2bbig(b) 5-stage pipeline (IF,ID,EX,MEM,WB); each stage 3 ns except MEM = 4 ns; 1000 instructions. (i) speedup vs single-cycle (ii) throughput increase (iii) latency decrease. [6]
Ξ£=3+3+3+4+3=16Β ns,tcβ=max=4Β ns,k=5,Β n=1000
(i) Speedup. Non-pipelined =1000Γ16=16000 ns; pipelined =(5+999)Γ4=4016 ns.
Speedup=16000/4016β3.98Γβ
(ii) Throughput. Steady-state throughput = one instruction per clock: non-pipelined 1/16 nsβ»ΒΉ β pipelined 1/4 nsβ»ΒΉ = 4Γ the throughput (overall, using totals, β 3.98Γ).
(iii) Latency. Single-instruction latency = non-pipelined 16 ns vs pipelined 5Γ4=20 ns. There is no decrease β latency actually rises by 4 ns. Pipelining trades slightly worse latency for much higher throughput.
Q3 β Memory & Cache CO3
3abig(a) Diagram a direct-mapped cache with capacity 4096 bytes and block size 16 bytes, 32-bit address. [4]
Block = 16 B = 4 words β offset = log2β16=4 bits (2 byte + 2 block-word). Lines = 4096/16=256 β index = log2β256=8 bits. Tag = 32β8β4=20 bits. Address split for a 4 KB, 16-byte-block direct-mapped cache.256 lines, each = valid + 20-bit tag + 128-bit data. Index picks the line; tag confirms the block.
3bsmall(b) How many total bits are required for the cache in Q3(a)? [3]
Data per line = 4 words Γ 32 = 128 bits. Per line = valid 1 + tag 20 + data 128 = 149.
Total=256Γ149=38,144Β bitsβ=37.25Β Kibits
3csmall(c) A cache has 2^n entries. How many degrees of associativity are possible? Which n-values give direct-mapped or fully associative? [3]
Possible associativities are 1,2,4,β¦,2n-way β n+1 configurations. The extremes are configurations, not n-values: 1-way = direct-mapped (each set = 1 line); 2n-way = fully associative (one set holds all lines). Any n β₯ 0 supports both extremes; only n = 0 (a single-line cache) makes direct-mapped and fully associative coincide.