---
title: "Problem set 1: RTL, logic and state machines"
heading: "Problem set 1: RTL design, combinational and sequential logic, and FSMs"
eyebrow: S3 · Problem set 1
type: problems
---

::: hook
These problems cover lessons 1 to 6: register counts and clock limits, multiplexer and comparator structures, counters, dividers and LFSRs, state machine encodings, simulation and synthesis pitfalls, and the widths and trees of parameterized hardware.
:::

::: pool
pick: 12

::: check
kind: parts
given: c = 40 | 70; n = 6 | 18; g = 20 | 35; s = 20 | 40

## A register-to-register path: {n} gates of {g} ps, clock-to-Q {c} ps, setup {s} ps.

::: part
answer: c + n*g + s
unit: ps
tolerance: 0.5%

### Minimum clock period?

::: misses
- [any] $t_{cq} + t_\text{logic} + t_\text{setup}$.
:::
:::

::: part
answer: 1/((c + n*g + s)*1e-12)/1e9
unit: GHz
tolerance: 1%

### Maximum frequency?

::: misses
- [any] Its reciprocal.
:::
:::

::: part
answer: 1/((c + n/2*g + s)*1e-12)/1e9
unit: GHz
tolerance: 1%

### If a register splits the logic into halves (the longer half has $\lceil n/2\rceil$ gates)?

::: misses
- [any] The longer half sets the period.
:::
:::
:::

::: check
kind: parts
given: N = 12 | 30; w = 8 | 32; d = 16 | 64

## A design: an {N}-state machine, a {d}-word × {w}-bit register file.

::: part
answer: ceil(log(N)/log(2)) + w*d
tolerance: 0

### Flip-flops with binary state encoding?

::: misses
- [any] $\lceil\log_2N\rceil + wd$.
:::
:::

::: part
answer: N + w*d
tolerance: 0

### With one-hot encoding?

::: misses
- [any] $N + wd$.
:::
:::
:::

::: check
kind: parts
given: N = 12 | 48; g = 25 | 40

## Selecting one of {N} inputs, at {g} ps per 2-to-1 multiplexer level.

::: part
answer: N - 1
tolerance: 0

### Multiplexers needed?

::: misses
- [any] N − 1.
:::
:::

::: part
answer: ceil(log(N)/log(2))*g
unit: ps
tolerance: 1%

### Delay as a balanced tree?

::: misses
- [any] $\lceil\log_2N\rceil$ levels.
:::
:::

::: part
answer: (N - 1)*g
unit: ps
tolerance: 1%

### As a priority chain?

::: misses
- [any] N − 1 levels.
:::
:::
:::

::: check
kind: parts
given: N = 12 | 40; g = 20 | 30

## An {N}-bit equality comparator from 2-input gates of {g} ps.

::: part
answer: 2*N - 1
tolerance: 0

### Gates?

::: misses
- [any] N XNORs, N − 1 ANDs.
:::
:::

::: part
answer: (1 + ceil(log(N)/log(2)))*g
unit: ps
tolerance: 1%

### Delay (XNOR plus AND tree)?

::: misses
- [any] One XNOR level plus $\lceil\log_2N\rceil$ AND levels.
:::
:::
:::

::: check
kind: parts
given: f = 25 | 125; t = 1.3 | 33 | 470

## A {f} MHz clock must produce a {t} kHz tick.

::: part
answer: f*1e3/t
tolerance: 0.1%

### Division ratio?

::: misses
- [any] $f_\text{clk}/f_\text{tick}$.
:::
:::

::: part
answer: ceil(log(f*1e3/t)/log(2))
tolerance: 0

### Counter bits?

::: misses
- [any] $\lceil\log_2N\rceil$.
:::
:::
:::

::: check
kind: parts
given: n = 10 | 20; f = 50 | 200

## An {n}-bit LFSR and an {n}-bit binary counter, clocked at {f} MHz.

::: part
answer: 2^n - 1
tolerance: 0

### LFSR states?

::: misses
- [any] $2^n - 1$.
:::
:::

::: part
answer: 2^n/(f*1e6)*1e3
unit: ms
tolerance: 0.1%

### Counter's wrap period?

::: misses
- [any] $2^n/f$.
:::
:::
:::

::: check
kind: parts
given: N = 6 | 14 | 25

## A state machine with {N} states.

::: part
answer: 2^ceil(log(N)/log(2)) - N
tolerance: 0

### Unused codes in binary?

::: misses
- [any] $2^{\lceil\log_2N\rceil} - N$.
:::
:::

::: part
answer: N - ceil(log(N)/log(2))
tolerance: 0

### Extra flip-flops for one-hot?

::: misses
- [any] $N - \lceil\log_2N\rceil$.
:::
:::
:::

::: check
kind: parts
given: L = 3 | 4 | 5 | 6 | 7 | 8

## A detector for a non-overlapping {L}-bit pattern.

::: part
answer: L
tolerance: 0

### Mealy states?

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

::: part
answer: L + 1
tolerance: 0

### Moore states?

::: misses
- [any] Plus the matched state.
:::
:::

::: part
answer: ceil(log(L + 0.5)/log(2))
tolerance: 0

### Binary flip-flops for the Moore version?

::: misses
- [any] $\lceil\log_2(L + 1)\rceil$.
:::
:::
:::

::: check
kind: parts
given: a = 2 | 5 | 8; b = 1 | 6 | 9; c = 3 | 7

## Registers a = {a}, b = {b}, c = {c} on one clock edge.

::: part
answer: b
tolerance: 0

### After `a <= b; b <= c; c <= a;`, what's a?

::: misses
- [any] Nonblocking reads old values.
:::
:::

::: part
answer: a
tolerance: 0

### And c?

::: misses
- [any] c takes a's old value.
:::
:::
:::

::: check
kind: parts
given: f = 100 | 250; c = 45 | 65; s = 25 | 45; g = 30 | 50

## A design must close timing at {f} MHz; flip-flops have {c} ps clock-to-Q and {s} ps setup; gates {g} ps.

::: part
answer: 1/(f*1e6)*1e12 - c - s
unit: ps
tolerance: 0.5%

### Logic budget per cycle?

::: misses
- [any] Period minus register overhead.
:::
:::

::: part
answer: floor((1/(f*1e6)*1e12 - c - s)/g + 0.001)
tolerance: 0

### Maximum logic depth, in gates?

::: misses
- [any] Budget over gate delay, rounded down.
:::
:::
:::

::: check
kind: boolean
vars: S1, S0, A, B, C, D
answer: ~S1 & ~S0 & A | ~S1 & S0 & B | S1 & ~S0 & C | S1 & S0 & D
ops: and, or, not

## Write a 4-to-1 multiplexer: A when (S1, S0) = 00, B for 01, C for 10, D for 11.

::: right
Right. One AND term per input, each enabled by its select code.
:::

::: misses
- [any] Not yet. Decode each select combination and AND it with its input.
:::
:::

::: check
kind: parts
given: n = 4 | 8 | 12; N = 3 | 10

## A {n}-bit binary counter feeds another clock domain; a {N}-state machine steps through its states in order.

::: part
answer: n
tolerance: 0

### Bits that change when the counter wraps to zero?

::: misses
- [any] All of them.
:::
:::

::: part
answer: ceil(log(N - 0.5)/log(2))
tolerance: 0

### Flip-flops for the machine in Gray code?

::: misses
- [any] Same as binary.
:::
:::
:::

::: check
kind: parts
given: N = 20 | 64 | 200; k = 4 | 6

## A parameterized OR of {N} inputs is mapped onto {k}-input LUTs, with a register after each level.

::: part
answer: ceil((N - 1)/(k - 1))
tolerance: 0

### How many LUTs does it take?

::: misses
- [any] $\lceil(N - 1)/(k - 1)\rceil$.
:::
:::

::: part
answer: ceil(log(N)/log(k) - 1e-9)
unit: cycles
tolerance: 0

### What is its latency?

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

::: check
kind: parts
given: D = 300 | 1000 | 2048; M = 128 | 512 | 1024; N = 10 | 50; W = 12 | 16

## A module is parameterized with a {D}-word memory, a counter that must hold the value {M}, and a sum of {N} values of {W} bits.

::: part
answer: ceil(log(D)/log(2) - 1e-9)
unit: bits
tolerance: 0

### How many address bits?

::: misses
- [any] $\lceil\log_2D\rceil$.
:::
:::

::: part
answer: ceil(log(M + 1)/log(2) - 1e-9)
unit: bits
tolerance: 0

### How many counter bits?

::: misses
- [ceil(log(M)/log(2) - 1e-9)] Holding M itself needs $\lceil\log_2(M + 1)\rceil$.
- [any] $\lceil\log_2(M + 1)\rceil$.
:::
:::

::: part
answer: W + ceil(log(N)/log(2) - 1e-9)
unit: bits
tolerance: 0

### How wide is the sum?

::: misses
- [any] $W + \lceil\log_2N\rceil$.
:::
:::
:::

::: check
kind: parts
given: D = 16 | 48 | 100; W = 8 | 18

## A generate loop builds a {D}-tap delay line of {W}-bit samples with no reset and no middle taps.

::: part
answer: D*W
tolerance: 0

### How many flip-flops would it take?

::: misses
- [any] Taps × width.
:::
:::

::: part
answer: ceil(D/32)*W
tolerance: 0

### How many 32-deep shift-register LUTs instead?

::: misses
- [any] $\lceil D/32\rceil$ per bit.
:::
:::
:::

::: check
kind: parts
given: n = 4 | 8; a = 300 | 700 | 2000; b = 100 | 900; v = 3 | 20

## An RTL review finds width and sign bugs.

::: part
answer: a + b - 2^n*floor((a + b)/2^n)

### An {n}-bit register receives {a} + {b}. What does it hold?

::: misses
- [a + b] It keeps only {n} bits.
- [any] Not yet. $(a + b) \bmod 2^n$.
:::
:::

::: part
answer: 2^n - v

### Compared as {n}-bit unsigned, what value does −{v} become?

::: misses
- [v] Two's complement wraps around: $2^n - v$.
- [any] Not yet. $2^n - v$.
:::
:::

::: right
Right. Silent truncation and sign mixing are why every result's width is sized on purpose.
:::
:::
:::
