E ExamMaster

Computer Architecture · Computer Architecture

ISA and CPU Time

The hardware contract: what an instruction is, how it names operands, and the three levers of CPU time.

A program is a list of instructions the hardware is required to carry out. This topic is that contract: what an instruction is, how it names its data, and why CPU time is the product of instruction count, cycles per instruction, and clock period. One instruction threads the whole course: LOAD R1, (R2) reads the word at the address in R2 — we use 0x1000 — into R1.

  • Computer Architecture
  • Hard level
  • 5 concepts
  • 5 practice questions

1ISA versus microarchitecture

The instruction set architecture, or ISA, is the contract a program is written against: the registers it may name, the instructions it may use, and what each instruction is required to do. Microarchitecture is how one particular chip implements that contract — a five-stage pipeline, a cache, a 2 GHz clock. Two chips can share one ISA and differ in every one of those implementation choices.

The ISA does not mention cache lines or pipeline stages. Those are microarchitectural. Change the pipeline and keep the ISA, and old programs still run. Change the ISA, and they do not — the compiler would have to emit different instruction bits.

Figure. The left box is the contract the program sees. The right box is how one chip keeps that contract. The running LOAD is the same instruction on both sides.

How it works

  1. ISAThe names the program may use: registers, opcodes, and what each instruction must do.
  2. MicroarchitectureThe chip's implementation: pipeline, cache, clock — invisible to the binary.
  3. Same binaryTwo chips that share an ISA run the same LOAD R1, (R2); they may take different time.
Who owns which fact
FactISAMicroarchitecture
LOAD R1, (R2) means "read the word R2 points to"yes
That read may hit a 32 KB cacheyes
The chip runs at 2 GHzyes
R1 and R2 are programmer-visible registersyes
A vendor ships a faster cache and a deeper pipeline but keeps the same instruction bits. Existing programs
  1. Still run — the ISA did not change
  2. Must be recompiled — the cache is part of the ISA
  3. Break, because pipeline stages are in the binary

Cache and pipeline are microarchitecture. The binary names ISA operations. Recompilation is needed only when the instruction bits themselves change.

2CPU time — the iron law

CPU time is how long the processor spends on a program. It is the product of three independent levers: \text{CPU time} = \text{Instruction count} \times \text{CPI} \times \text{Clock cycle time}. Instruction count is how many instructions actually run. CPI, cycles per instruction, is the average number of clock ticks each of those instructions occupies. Clock cycle time is the length of one tick — at 2 GHz that tick is 0.5 ns.

Halving any one factor halves total time. A better compiler that emits fewer instructions moves the first lever. A pipeline that overlaps work moves CPI. Faster silicon moves the clock. Exam questions and design reviews both ask which lever a change actually moved — not whether "the computer got faster" in the abstract.

Figure. Three multiplicative factors. The bar heights are not a measured program — they mark that each lever is independent. Cut any one, or improve another enough to compensate.

How it works

  1. Instruction countHow many instructions the program executes — algorithm and compiler, and which ISA they target.
  2. CPIAverage clock cycles per instruction — pipelining lowers it toward 1; hazards raise it.
  3. Clock cycle timeSeconds per cycle — a 2 GHz clock is 0.5 ns per tick.
Which lever did the change move?
ChangeICCPIClock
Compiler emits fewer instructions
Deeper pipeline, fewer stalls
Faster silicon, higher GHz
Branch prediction cuts mispredicts

Three levers on one program

A processor runs at 2 GHz with CPI = 1.5 on a program of 4 \times 10^9 instructions. How long does the CPU spend?

  • Clock cycle time = 1 / (2 \times 10^9) s0.5 ns
  • CPU time = 4 \times 10^9 \times 1.5 \times 0.5 ns3.0 \times 10^9 ns
  • 3.0 \times 10^9 ns3 s

Pro tip. Write the cycle time first. Forgetting CPI, or treating 2 GHz as 2 ns, doubles or halves the answer.

A processor runs at 2 GHz with CPI = 1.5 on a program of 4 \times 10^9 instructions. CPU time is closest to
  1. 3 s
  2. 6 s
  3. 1.5 s

Cycle time = 0.5 ns. CPU time = 4 \times 10^9 \times 1.5 \times 0.5 ns = 3 s. 6 s doubles the cycle time; 1.5 s drops the CPI factor.

3One instruction: LOAD R1, (R2)

The running example for this course is one instruction: `LOAD R1, (R2)`. The parentheses mean "use R2 as a pointer". The CPU reads the address stored in R2 — we will use 0x1000 — then reads the word at that address into register R1. That whole action is one instruction in the ISA, so it adds 1 to the iron law's instruction count.

A different ISA might need two instructions to do the same job (compute an address, then load). That is how ISA design moves the instruction-count lever. The later topics keep this same LOAD: a pipeline will overlap its stages, a cache will sit under its memory read, and an I/O path appears if 0x1000 names a device register instead of a DRAM word.

Figure. R2 supplies the address 0x1000. Memory returns the word stored there. R1 receives that word. One ISA instruction, two hardware reads: the register, then the memory word.

How it works

  1. Read R2R2 holds an address. In this course that address is 0x1000.
  2. Read memoryThe CPU reads the word stored at 0x1000.
  3. Write R1That word is copied into R1. The instruction count for this line is 1.

The running instruction

LOAD R1, (R2)   ; R2 holds 0x1000
; R1 ← memory[0x1000]

Instruction count for a load loop

A loop runs `LOAD R1, (R2)` once per iteration for 1000 iterations, and nothing else. What is the instruction count?

  • Instructions per iteration1 LOAD
  • Iterations1000
  • Instruction count1000

Pro tip. The parentheses do not make the load free. One ISA instruction still counts as one, even when a register holds the address.

LOAD R1, (R2) with R2 = 0x1000 reads the word at
  1. memory address 0x1000
  2. register R2 itself, not memory
  3. memory address 0x1000 + R1

Register-indirect: R2 is the pointer. The word comes from memory[0x1000] into R1. The load does not read R2 as data, and it does not add R1 to the address.

4Addressing modes

An addressing mode is the rule the ISA uses to form the effective address of an operand — the actual location the instruction will read or write. Immediate embeds a constant in the instruction bits. Direct writes a memory address into the instruction. Register uses a register as the operand. Register-indirect, the mode of `LOAD R1, (R2)`, uses a register as a pointer to memory. Indirect goes one step further: the instruction names a memory word that itself holds the address. Indexed adds a displacement to a base register, the usual pattern for `a[i]`.

The mode decides how many memory references the instruction needs after it has been fetched. Immediate and register need zero data fetches. Our LOAD needs one. Memory-indirect needs two: fetch the pointer, then fetch the operand.

Figure. Addressing modes differ in how the effective address is computed. The middle box is our running LOAD: R2 already holds 0x1000, so the effective address is the contents of R2.

How it works

  1. Immediate / registerOperand is in the instruction or a register — no extra memory fetch for the data itself.
  2. Direct / register-indirectDirect names a memory address in the instruction. Register-indirect, our LOAD, names a register that holds the address.
  3. Indirect / indexedIndirect fetches a pointer from memory first. Indexed adds a displacement to a base register, typically for an array.
Addressing modes at a glance
ModeEffective addressData memory refs
ImmediateOperand in the instruction0
RegisterRegister contents0
DirectAddress field1
Register-indirectRegister points to memory1
IndirectM[address field]2
IndexedBase + index (+ disp)1
LOAD R1, (R2) uses which addressing mode?
  1. Register-indirect
  2. Direct
  3. Immediate

Parentheses around R2 mean the register holds a memory address. Direct would put 0x1000 in the instruction bits; immediate would put the data value in the instruction bits.

5One instruction, five jobs

Before overlapping anything, picture `LOAD R1, (R2)` occupying the whole machine. Fetch reads the instruction bits from memory at the program counter. Decode reads the opcode and the two register numbers. Execute forms the effective address 0x1000 from R2. Memory reads the word at 0x1000. Write-back copies that word into R1. In a non-pipelined machine the next instruction does not start until write-back finishes.

Those five jobs are why a five-stage pipeline can help: each job becomes a stage, and the next instruction can start its fetch while this LOAD is still in memory. That overlap is the next topic. The ISA has not changed — the same LOAD still means the same thing.

Figure. Five jobs in order for a single LOAD. MEM is the read at 0x1000; WB writes R1. Nothing else is in the machine until WB finishes.

How it works

  1. FetchRead the instruction bits at the program counter.
  2. DecodeRead the opcode and register numbers — LOAD, R1, R2.
  3. ExecuteForm the effective address from R2: 0x1000.
  4. MemoryRead the word at 0x1000.
  5. Write-backPut that word in R1. Only then may the next instruction start.
On a non-pipelined machine, the instruction after LOAD R1, (R2) starts
  1. After the LOAD writes R1
  2. As soon as the LOAD is fetched
  3. During the LOAD's memory read

Without overlap, the machine finishes write-back first. Starting at fetch, or during the memory read, is the pipelined schedule — the next topic.

Notes

  • Pipelining overlaps instruction stages (IF, ID, EX, MEM, WB) to increase throughput; hazards (structural, data, control) can stall the pipeline.
  • Data hazards are resolved by forwarding/bypassing or stalls; control hazards by branch prediction; the ideal speedup approaches the number of stages.
  • Cache mapping: direct-mapped (one line per set), fully associative (any line), and k-way set associative (k lines per set) trade cost vs miss rate.
  • Locality of reference (temporal and spatial) is why caches work; a cache hit avoids the slower main-memory access.
  • Addressing modes include immediate, direct, indirect, register, register-indirect, and indexed; they determine how operand addresses are computed.

Formulas

  • CPU time = Instruction count * CPI * clock cycle time (the iron law of performance).
  • Pipeline speedup = \frac{k \times n}{k + (n-1)} for k stages and n instructions; ideal speedup \to k.
  • Effective (average) memory access time = Hit time + Miss rate * Miss penalty.
  • Cache blocks = cache size / block size; set count = blocks / associativity.
  • For an ideal pipeline, throughput = 1 instruction per clock cycle after the pipeline fills.

Exam traps & shortcuts

  • For pipeline speedup with large n, the answer approaches the number of stages k.
  • AMAT = Hit time + Miss rate x Miss penalty — plug directly; multi-level caches nest this formula.
  • Direct-mapped = 1-way associative; fully associative = one big set — the extremes of set-associativity.

Reference tables

The iron law is the only formula in this topic. Pipeline speedup and AMAT belong to the topics that teach them.

Formula sheet
QuantityFormulaWatch for
CPU timeIC × CPI × clock cycle timeThree independent levers
Clock cycle time1 / clock frequency2 GHz → 0.5 ns, not 2 ns
Data refs, register-indirect1 after the instruction is fetchedOur LOAD R1, (R2)

Recap

The contract, then the three levers, then the one instruction that the later topics reuse.

ISA
What the program may say. Cache and pipeline are not in the ISA.
Iron law
CPU time = IC × CPI × clock. Name which lever a change moved.
LOAD R1, (R2)
Register-indirect: R2 holds 0x1000; the word at 0x1000 lands in R1; IC += 1.
Modes
Immediate/register = 0 data refs; register-indirect = 1; memory-indirect = 2.
Five jobs
IF → ID → EX → MEM → WB, serial until the next topic overlaps them.

Practise ISA and CPU Time

Reading is free and needs no account. Practice, mocks and progress live in the app.

  • 5 exam-style questions on this topic, with explanations
  • A 4-question practice set that ends the chapter
  • Timed mocks scored with the real marking scheme
  • Readiness tracked per topic, kept on your device
Continue with Google — freeNo card, no trial. Works offline once installed.