---
title: Problem set 7
heading: "Problem set 7: building the processor"
eyebrow: C8 · Problem set 7
type: problems
---

::: hook
These problems use lessons 35 to 37: the single-cycle datapath and its timing, the control unit, and the multi-cycle processor. Times are in picoseconds, and instruction words are given in hex.
:::

::: pool
pick: 12

::: check
kind: parts
given: P = 30 | 50; M = 150 | 250; R = 80 | 120; A = 100 | 180; X = 25; S = 40 | 70

## A single-cycle processor has $t_{pcq}$ = {P}, memories of {M}, a register-file read of {R}, an ALU of {A}, a multiplexer of {X} and a register-file setup of {S} ps.

::: part
answer: P + 2*M + R + A + X + S
unit: ps
tolerance: 0

### What is the clock period?

::: misses
- [P + M + R + A + X + S] A load reads memory twice.
- [any] The load's path through every unit.
:::
:::

::: part
answer: 1000/(P + 2*M + R + A + X + S)
unit: GHz
tolerance: 0.5%

### What is the clock frequency?

::: misses
- [any] One over the period.
:::
:::
:::

::: check
kind: parts
given: T = 700 | 750 | 900; A = 120 | 150; u = 300 | 400; m = 1 | 3

## A {u} ps multiplier is added beside the {A} ps ALU of a {T} ps single-cycle processor, on the critical path. {m}% of instructions multiply.

::: part
answer: T + u - A
unit: ps
tolerance: 0

### What is the new clock period?

::: misses
- [T + u] It replaces the ALU's delay on the path; it doesn't add to it.
- [any] The path grows by the difference.
:::
:::

::: part
answer: (T + u - A)/T
tolerance: 0.5%

### By what factor does every program slow down, multiplies or not?

::: misses
- [any] The ratio of periods.
:::
:::
:::

::: check
kind: parts
given: w = 8463619 | 10560547 | 12944691 | 10486419 | 6457443

## An instruction word is {w:hex8}.

::: part
answer: floor(w/4096) - 8*floor(w/32768)
tolerance: 0

### What is funct3 (bits 14:12)?

::: misses
- [any] Shift right by 12, keep 3 bits.
:::
:::

::: part
answer: floor(w/32768) - 32*floor(w/1048576)
tolerance: 0

### What is rs1 (bits 19:15)?

::: misses
- [any] Shift right by 15, keep 5 bits.
:::
:::
:::

::: check
kind: parts
given: w = 4290847491 | 3221389971 | 4293918867 | 4286653059

## An I-type instruction is {w:hex8}.

::: part
answer: floor(w/2^20) - 4096*step(floor(w/2^20) - 2047.5)
tolerance: 0

### What immediate does the immediate generator produce?

::: misses
- [floor(w/2^20)] Bit 31 is the sign: sign-extend the 12 bits.
- [any] Bits 31:20, sign-extended.
:::
:::

::: part
answer: w - 128*floor(w/128)
tolerance: 0
base: 16
width: 2

### What is its opcode?

::: misses
- [any] The low 7 bits.
:::
:::
:::

::: check
kind: parts
given: w = 10560547 | 4269026851 | 1076765731

## A store instruction is {w:hex8}.

::: part
answer: floor(w/2^25)*32 + floor(w/128) - 32*floor(w/4096) - 4096*step(floor(w/2^25)*32 + floor(w/128) - 32*floor(w/4096) - 2047.5)
tolerance: 0

### What is its offset? (S-type: bits 31:25 are imm[11:5], bits 11:7 are imm[4:0].)

::: misses
- [any] Join the two pieces, then sign-extend 12 bits.
:::
:::

::: part
answer: floor(w/2^20) - 32*floor(w/2^25)
tolerance: 0

### Which register does it store (rs2)?

::: misses
- [any] Bits 24:20.
:::
:::
:::

::: check
kind: parts
given: v = 305422335 | 3735928559 | 180164608

## `li t0, {v:hex8}` becomes `lui t0, hi` then `addi t0, t0, lo`, where `addi` sign-extends lo.

::: part
answer: floor((v + 2048)/4096)
tolerance: 0
base: 16
width: 5

### What is hi?

::: misses
- [floor(v/4096)] If bit 11 is set, lo is negative, so hi must be one more.
- [any] The top 20 bits of v + 0x800.
:::
:::

::: part
answer: v - 4096*floor((v + 2048)/4096)
tolerance: 0

### What is lo, as a signed number?

::: misses
- [any] v − hi · 4096.
:::
:::
:::

::: check
kind: parts
given: A = 256 | 1024 | 8192; d = -64 | 40 | 2000

## A `jal ra, {d}` sits at address {A}.

::: part
answer: A + 4
tolerance: 0

### What does ra receive?

::: misses
- [any] The address of the next instruction.
:::
:::

::: part
answer: A + d
tolerance: 0

### Where does execution continue?

::: misses
- [A + 4 + d] The offset is from the jump's own address.
- [any] PC + offset.
:::
:::
:::

::: check
kind: parts
given: l = 20 | 25 | 30; s = 8 | 12; b = 10 | 15 | 20; j = 2 | 4; T = 250 | 320

## A program is {l}% loads, {s}% stores, {b}% branches and {j}% jumps; the rest are R-type and I-type arithmetic. On the multi-cycle processor, loads take 5 cycles, branches 3 and the rest 4, at {T} ps a cycle.

::: part
answer: 5*l/100 + 3*b/100 + 4*(1 - l/100 - b/100)
tolerance: 0.5%

### What is the CPI?

::: misses
- [any] Only loads and branches differ from 4.
:::
:::

::: part
answer: (5*l/100 + 3*b/100 + 4*(1 - l/100 - b/100))*T
unit: ps
tolerance: 0.5%

### What is the time per instruction?

::: misses
- [any] CPI × period.
:::
:::
:::

::: check
kind: parts
given: P = 30 | 40; X = 25 | 30; A = 120 | 200 | 260; M = 200 | 250; S = 40 | 50

## A multi-cycle datapath has $t_{pcq}$ = {P}, multiplexers of {X}, an ALU of {A}, a memory of {M} and a setup of {S} ps.

::: part
answer: P + X + (A + X + M + abs(A + X - M))/2 + S
unit: ps
tolerance: 0

### What is the clock period?

::: misses
- [any] $t_{pcq} + t_\text{mux} + \max(t_\text{ALU} + t_\text{mux}, t_\text{mem}) + t_\text{setup}$.
:::
:::

::: part
answer: 3*(P + X + (A + X + M + abs(A + X - M))/2 + S)
unit: ps
tolerance: 0

### How long does a branch take?

::: misses
- [any] Three cycles.
:::
:::
:::

::: check
kind: parts
given: N = 100 | 1000; k = 1 | 2; r = 2 | 4; T = 250 | 320; U = 700 | 800

## A loop body of {k} loads, {r} R-type instructions and a branch runs {N} times. The multi-cycle clock is {T} ps; the single-cycle clock is {U} ps.

::: part
answer: N*(5*k + 4*r + 3)*T/1000
unit: ns
tolerance: 0.5%

### How long does the multi-cycle processor take?

::: misses
- [any] Cycles per pass × passes × period.
:::
:::

::: part
answer: N*(k + r + 1)*U/1000
unit: ns
tolerance: 0.5%

### And the single-cycle processor?

::: misses
- [any] One cycle per instruction.
:::
:::
:::

::: check
kind: parts
given: U = 700 | 750 | 900; c = 3.9 | 4.1 | 4.3

## A single-cycle processor runs at {U} ps; a multi-cycle design for the same instructions averages a CPI of {c}.

::: part
answer: U/c
unit: ps
tolerance: 0.5%

### Below what clock period would the multi-cycle design be faster?

::: misses
- [any] $U / \text{CPI}$.
:::
:::

::: part
answer: U/5
unit: ps
tolerance: 0.5%

### Below what period would even its 5-cycle loads be no slower?

::: misses
- [any] $U/5$.
:::
:::
:::

::: check
kind: parts
given: S = 128 | 512 | 2048; W = 32 | 56 | 96

## A microprogrammed control unit has {S} micro-instructions of {W} bits.

::: part
answer: S*W/8
unit: bytes
tolerance: 0

### How big is its control store?

::: misses
- [S*W] That's bits.
- [any] $SW/8$.
:::
:::

::: part
answer: round(log(S)/log(2))
tolerance: 0

### How many bits does its micro-PC need?

::: misses
- [any] $\log_2 S$.
:::
:::
:::

::: check
kind: parts
given: s = 10 | 12 | 19 | 27

## A multi-cycle control state machine has {s} states.

::: part
answer: ceil(log(s)/log(2))
tolerance: 0

### How many state flip-flops with binary encoding?

::: misses
- [any] $\lceil \log_2 s \rceil$.
:::
:::

::: part
answer: s
tolerance: 0

### With one-hot?

::: misses
- [any] One per state.
:::
:::
:::

::: check
kind: parts
given: A = 512 | 4096; d = -12 | 16 | 200; e = 0 | 1

## A `beq` at {A} with offset {d} compares two registers; Zero = {e}.

::: part
answer: A + 4 + (d - 4)*e
tolerance: 0

### What is the next PC?

::: misses
- [any] PC + offset when Zero is 1, PC + 4 when it's 0.
:::
:::

::: part
answer: A + d
tolerance: 0

### What target did the branch adder compute, either way?

::: misses
- [any] PC + offset, computed every time.
:::
:::
:::

::: check
kind: parts
given: f = 32 | 128; d = 8 | 16

## A main decoder is built as a ROM addressed by the 7-bit opcode, with {f} output signals; an ALU decoder as a ROM addressed by ALUOp (2 bits), funct3 and funct7's bit 5, with {d} outputs.

::: part
answer: 2^7*f
tolerance: 0

### How many bits does the main decoder ROM hold?

::: misses
- [any] $2^7$ words of {f} bits.
:::
:::

::: part
answer: 2^6*d
tolerance: 0

### And the ALU decoder ROM?

::: misses
- [any] 2 + 3 + 1 = 6 address bits.
:::
:::
:::
:::
