Computer Architecture, Past Papers, UOS Main Campus

Computer Architecture Past Paper 2015 – MSc IT 4th Term UOS (IT-695)

ProgramMSc IT
Term4th
Year2015
Course codeIT-695
AnswersSolved ✓

University of Sargodha M.Sc. IT 4th term Computer Architecture (IT-695) paper, 2015 exam (80 marks, 2:30 hours). The year on the original is overwritten by hand; it reads 2015, and the subjective part is the same as the BSCS 4th term 2015 paper. The paper is retyped below without the handwritten notes, followed by solved answers for all 16 short questions and all six subjective questions: cache memory, multiprocessors, memory hierarchy, ILP and precise exceptions, addressing modes and the 8086 architecture.

Solved answers

Q1 – Short answers (16 × 2)

1. Two major factors in architecture. Performance and cost (price/performance). Designers also weigh power consumption; the classic pair is instruction set architecture (what the programmer sees) and organisation/implementation (how it is built).

2. Where is Flash memory in the hierarchy? At the secondary-storage level, below main memory (DRAM) and above magnetic disk/tape: used in SSDs, USB drives and memory cards; it is non-volatile and slower than DRAM.

3. “Each block maps to only two lines of a cache.” True for a 2-way set-associative cache: a block maps to one set (set = block mod number of sets) and can be placed in either of the two lines of that set. It is false for direct-mapped (one line) and fully associative (any line) caches. Diagram (8 lines, 4 sets): blocks 0, 4, 8, 12 → set 0 (lines 0 or 1); blocks 1, 5, 9, 13 → set 1 (lines 2 or 3); and so on.

4. Instruction cache. A cache that holds only instructions (code) fetched by the CPU; it is read-only for the processor. Separate I-cache and D-cache (split L1) let instruction fetch and data access happen in the same cycle.

5. Data cache. A cache that holds data operands used by load and store instructions; it supports both reads and writes (write-through or write-back).

6. MISD. Multiple Instruction, Single Data (Flynn): several processing units execute different instructions on the same data stream. Rare in practice; examples are fault-tolerant systems (space shuttle flight computers) and systolic arrays.

7. Vector vs scalar data. Scalar = a single value processed by one instruction. Vector = an array of values processed by one vector/SIMD instruction in parallel, e.g. adding two 64-element arrays.

8. Threads. The smallest unit of execution scheduled by the OS; threads of one process share code, data and files but have their own PC, registers and stack.

9. How threads improve performance. Threads run in parallel on multiple cores/hyper-threads, hide latency (one thread computes while another waits for I/O or memory), improve responsiveness and share resources cheaply compared with processes.

10. Opcode. The operation code – the part of a machine instruction that specifies the operation to perform (ADD, LOAD, JUMP); the rest of the instruction holds operands/addresses. In MIPS it is the 6-bit field bits 31–26.

11. Amdahl’s Law. Speedupoverall = 1 / ((1 − f) + f/s), where f is the fraction of time that can be improved and s its speed-up; the unimproved part limits total gain.

12. Moore’s law. The number of transistors on a chip doubles about every two years (Gordon Moore, 1965/1975).

13. Types of locality. Temporal (recently used items will be used again soon) and spatial (items near recently used addresses will be used soon); sequential locality is a special case of spatial.

14. Measuring performance. Execution time; CPU time = IC × CPI × clock cycle time; throughput; MIPS/FLOPS; benchmarks such as SPEC.

15. Register renaming. A technique that maps architectural registers to a larger set of physical registers so that WAR and WAW (name) dependences are removed, allowing more instructions to execute out of order (used in Tomasulo’s algorithm and modern CPUs).

16. Three pipeline issues. Structural hazards, data hazards and control (branch) hazards; exceptions are a fourth issue.

Q2 – Cache memory, mapping functions and replacement algorithms

Cache memory is a small, very fast SRAM memory placed between the CPU and main memory. It keeps copies of recently used blocks of main memory. When the CPU needs a word it checks the cache first: if present it is a hit; otherwise it is a miss and the whole block is brought from memory into a cache line. Performance is measured by hit ratio and average memory access time: AMAT = hit time + miss rate × miss penalty.

Main memory address is split into fields: tag, line/set index and word (offset). Each cache line stores a tag, a valid bit (and a dirty bit for write-back) and the data block.

Mapping functions

  • Direct mapping – each block goes to exactly one line: line = block number mod number of lines. Address = tag | line | word. Simple and fast (one comparison), but two blocks that map to the same line keep replacing each other (conflict misses).
  • Associative mapping – a block can be placed in any line. Address = tag | word. All tags are compared in parallel. Most flexible, fewest conflict misses, but expensive comparison hardware.
  • Set-associative mapping – the cache is divided into sets of k lines (k-way). A block maps to one set (set = block number mod number of sets) and may go in any line of that set. Address = tag | set | word. A practical compromise; 2-, 4- and 8-way caches are common.

Example: 64 KB cache, 4-byte blocks, 16 MB memory (24-bit address). Direct mapped: 16K lines → word 2 bits, line 14 bits, tag 8 bits. Fully associative: tag 22 bits, word 2 bits. 2-way set associative: 8K sets → word 2, set 13, tag 9 bits.

Replacement algorithms (needed for associative and set-associative caches when the set is full):

  • LRU (Least Recently Used) – replace the line not used for the longest time; best in practice, uses usage bits/counters.
  • FIFO – replace the line that has been in the cache longest (round-robin pointer).
  • LFU (Least Frequently Used) – replace the line with the fewest references (counter per line).
  • Random – pick any line at random; cheap and only slightly worse than LRU.

Write policies (write-through, write-back) and multilevel caches (L1, L2, L3) complete the cache design.

Q3 – Multiprocessor

A multiprocessor is a computer with two or more CPUs (or cores) that share main memory and I/O under one operating system, to increase throughput, speed up parallel programs and improve reliability. In Flynn’s taxonomy it is an MIMD machine.

Types by memory organisation

  • Shared-memory (tightly coupled) – UMA/SMP: all processors share one memory through a bus or crossbar with equal access time. Easy to program; the bus limits scaling to a few tens of processors.
  • NUMA (Distributed shared memory): each node has local memory but all memory is in one address space; local access is faster than remote access. Scales to hundreds of processors.
  • Distributed-memory (loosely coupled) / message passing: each processor has private memory and processors communicate by sending messages (clusters, MPI).

Interconnection networks: shared bus, crossbar switch, multistage networks (Omega), mesh, ring, hypercube.

Key issues

  • Cache coherence – several caches may hold copies of the same block; a write by one CPU must be seen by others. Solved by snooping protocols (MSI/MESI, write-invalidate) on buses and directory-based protocols in NUMA.
  • Synchronisation – locks, semaphores and barriers built on atomic instructions (test-and-set, compare-and-swap, LL/SC).
  • Memory consistency – rules about the order in which writes become visible (sequential consistency, relaxed models).
  • Load balancing and scheduling of threads across processors.

Advantages: higher throughput, parallel speed-up, fault tolerance (graceful degradation), cost sharing of memory and I/O. Disadvantages: complex hardware and OS, coherence and synchronisation overhead, speed-up limited by Amdahl’s law. Multicore chips (Intel Core i7, AMD Ryzen) are today’s common multiprocessors.

Q4 – Memory hierarchy design

No single memory is fast, large and cheap at the same time, so computers use a hierarchy: small, fast, costly memories near the CPU and large, slow, cheap memories further away. Because of locality most accesses are satisfied by the upper levels, so the system appears almost as fast as the top level and as large as the bottom level.

LevelTechnologyTypical sizeAccess time
Registersflip-flops in CPU< 1 KB< 1 ns
L1 cacheSRAM on core32–64 KB~1 ns
L2 / L3 cacheSRAM on chip256 KB – 32 MB3–15 ns
Main memoryDRAM4–64 GB50–100 ns
Secondary storageSSD / magnetic disk0.5–4 TB0.1 ms – 10 ms
Tertiary/backuptape, optical, cloudvery largeseconds

Design issues (the four questions for each level):

  1. Block placement – where can a block be placed? (direct mapped, set-associative, fully associative).
  2. Block identification – how is a block found? (tag, index, offset; valid bit; page tables and TLB for virtual memory).
  3. Block replacement – which block is replaced on a miss? (LRU, FIFO, random).
  4. Write strategy – write-through or write-back, with write-allocate or no-write-allocate.

Performance: AMAT = Hit timeL1 + Miss rateL1 × (Hit timeL2 + Miss rateL2 × Miss penaltyL2). Designers reduce miss rate (larger blocks, larger caches, higher associativity, prefetching), miss penalty (multilevel caches, critical word first, write buffers) and hit time (small simple L1, virtual-indexed caches).

Virtual memory is the level between main memory and disk: programs use virtual addresses, translated by page tables and a TLB, with pages loaded on demand. It gives each process a large private address space and protection.

Q5 – Instruction-level parallelism and dynamic handling of exceptions

Instruction-level parallelism (ILP) is the overlap of execution of independent instructions within one program. Techniques that exploit ILP:

  • Pipelining – different stages of several instructions run at once.
  • Superscalar execution – several instructions are issued per clock to multiple functional units.
  • Dynamic scheduling (out-of-order execution) – Tomasulo’s algorithm with reservation stations and register renaming lets an instruction run as soon as its operands are ready, removing WAR/WAW hazards.
  • Branch prediction and speculation – instructions after a predicted branch are executed speculatively.
  • Static techniques – loop unrolling, compiler scheduling, VLIW.

Limits on ILP are true data dependences, control dependences, limited registers and functional units, and memory latency.

Dynamic handling of exceptions. With out-of-order and speculative execution an instruction may raise an exception (overflow, page fault, divide by zero) before older instructions have finished, or may itself be on a wrongly predicted path. To keep exceptions precise the processor uses a reorder buffer (ROB):

  1. Instructions are issued in order and given a ROB entry; they execute out of order and write results into the ROB, not into the registers.
  2. If an instruction causes an exception, the exception is only recorded in its ROB entry.
  3. Instructions commit (retire) in program order. When the faulting instruction reaches the head of the ROB, the exception is raised: all later instructions in the ROB are flushed, the PC of the faulting instruction is saved (EPC) and control passes to the handler.
  4. If the instruction was on a mispredicted path it is flushed before it reaches the head, so its exception is never raised.

This way the machine state looks exactly as if instructions had executed one at a time, so the OS can handle the exception and restart the program.

Q6 – Five addressing modes

ModeMeaningExample
ImmediateOperand is a constant inside the instructionMOV AX, 5 / addi $t0,$t1,5
RegisterOperand is in a CPU registerADD AX, BX
Direct (absolute)Instruction holds the memory address of the operandMOV AX, [1000h]
Register indirectA register holds the address of the operandMOV AX, [BX]
Indexed / base + displacementEA = register + constant offsetlw $t0, 8($s1), MOV AX, [SI+4]
Indirect (memory)Memory word holds the address of the operandEA = M[1000h]
PC-relativeEA = PC + offset; used for branchesbeq $t0,$t1,label

Immediate is fastest (no memory access) but limited in size; register is fast with short instructions; direct is simple but the address field limits the range; register indirect and indexed suit pointers and arrays; PC-relative gives position-independent code.

Q7 – Architecture of a processor (8086)

The Intel 8086 is a 16-bit processor with a 20-bit address bus (1 MB). It is divided into two units that work in parallel (an early form of pipelining):

+------------------------- BIU (Bus Interface Unit) -------------------------+
|  Segment registers: CS  DS  SS  ES      IP (instruction pointer)           |
|  Address adder (segment x 16 + offset -> 20-bit physical address)          |
|  6-byte instruction queue  <-- prefetch -->  bus control  <--> system bus  |
+----------------------------------+-----------------------------------------+
                                   | instruction bytes
+----------------------------------v------- EU (Execution Unit) ------------+
|  Control unit / instruction decoder                                        |
|  General registers: AX(AH,AL) BX(BH,BL) CX(CH,CL) DX(DH,DL)                |
|  Pointer/index: SP  BP  SI  DI          ALU (16-bit)     FLAGS register    |
+----------------------------------------------------------------------------+
  • BIU fetches instructions and data, computes 20-bit physical addresses (segment × 16 + offset) and keeps a 6-byte prefetch queue filled while the EU executes.
  • EU decodes and executes instructions using the ALU, general-purpose registers (AX, BX, CX, DX), pointer and index registers (SP, BP, SI, DI) and the flag register (CF, PF, AF, ZF, SF, TF, IF, DF, OF).
  • Because the BIU prefetches while the EU executes, fetch and execute overlap and the processor is faster than a strictly sequential design.
Save this paper for offline studyDownload the question paper, or save the paper together with all solved answers as a PDF.
↓ Download Paper (JPG)

About Saif R

An educator and technology enthusiast passionate about empowering students through quality education and digital learning. Dedicated to making academic resources and opportunities accessible to everyone.