Kmila
Practice

Practice exercises

Solve real digital design problems against hidden test cases. Three modalities, three difficulties, one waveform that has to match.

Difficulty
Modality
01 · From zero

Build from zero

Read the spec, draft the entity body, prove it against the test cases.

AND gate

Two-input AND gate.

Easy

4-bit equality comparator

Output high when a equals b.

Easy

2-to-4 decoder

One-hot output for 2-bit input.

Easy

Half-adder

Two inputs, two outputs — write the sum and carry-out from scratch.

Easy

Half-subtractor

Compute a − b on single bits — output diff and borrow.

Easy

3-input majority voter

Output the majority of three single-bit inputs.

Easy

2-to-1 multiplexer

Pick a or b based on sel.

Easy

4-to-1 multiplexer

Select one of four inputs by 2-bit sel.

Easy

NAND gate

Two-input NAND.

Easy

NOR gate

Two-input NOR.

Easy

NOT gate

Single-input inverter.

Easy

OR gate

Two-input OR gate.

Easy

Even parity generator

4-bit input — output 1 if odd number of 1s (so total becomes even).

Easy

XNOR gate

Two-input exclusive-NOR.

Easy

XOR gate

Two-input exclusive-OR.

Easy

4-to-2 priority encoder

Encode highest active bit (one-hot in) into 2-bit y.

Medium

4-bit adder

4-bit a + b + cin → sum (4) and cout.

Medium

Divide-by-4 clock

Generate a clock at clk/4.

Medium

Greater/equal/less comparator

4-bit unsigned a vs b — three flag outputs.

Medium

4-bit synchronous counter

Increments q each rising edge; async reset.

Medium

Rising-edge detector

Outputs a 1-clock pulse on every 0→1 transition of d.

Medium

Full-adder

a + b + cin → sum, cout.

Medium

3-bit Gray code

Convert 3-bit binary to Gray code.

Medium

Load register (4-bit)

Loads d into q when load=1 on rising edge.

Medium

4-to-1 mux with enable

Output 0 when en=0; otherwise route input by sel.

Medium

One-hot to binary

Convert a 4-bit one-hot input to 2-bit binary.

Medium

8-bit left shift register

Shift left on each rising clock edge; serial input din.

Medium

T flip-flop

Toggles q when t=1 on a rising edge.

Medium

Toggle register with enable

Toggle q each cycle when en=1.

Medium

4-bit up/down counter

+1 when dir=1, −1 when dir=0; async reset.

Medium

8-bit ALU

4-op ALU: add / sub / and / or selected by 2-bit op.

Hard

Round-robin arbiter (4)

Grant one of four requests in rotating priority.

Hard

CORDIC iteration step

Single CORDIC step: x' = x ± y, y' = y ∓ x, signed by dir.

Hard

CRC-8 serial accumulator

Update an 8-bit CRC by feeding one bit per clock; reset to 0.

Hard

Button debouncer

Output flips only after the input has been stable for N cycles.

Hard

FIFO empty/full flags

Track count of pushes vs pops for a depth-4 queue; output flags only.

Hard

Hamming(7,4) encoder

Append three parity bits to a 4-bit data word.

Hard

8-bit LFSR

Maximal-length LFSR with taps at 8,6,5,4. Reset to 0xFF.

Hard

Manchester encoder

For each bit period emit two half-bits — '01' or '10'.

Hard

4-bit unsigned multiplier

a × b → 8-bit product. Combinational.

Hard

PWM generator (4-bit duty)

Output high while a 4-bit free-running counter is below duty.

Hard

SPI master shift

Generate sclk and shift the MSB of a register on mosi.

Hard

4-word stack flags

Track push/pop on a depth-4 stack; expose full/empty.

Hard

Traffic-light FSM

3-state traffic light: red → green → yellow → red.

Hard

UART receiver FSM

Idle → start → data → stop, controlled by rx serial input.

Hard
02 · Fix the bug

Find and fix the bug

A working-ish design with a planted defect — find it and patch the architecture.

2-bit add — no carry chain

The carry between bits is dropped.

Easy

3-input AND — input dropped

Output ignores c.

Easy

AND that's an OR

Author wrote `or` instead of `and`.

Easy

Comparator missing a bit

Compares only 3 of 4 bits.

Easy

Decoder — missing line

One output line never asserts.

Easy

Encoder — wrong priority

Lower bit takes precedence over higher.

Easy

Equality with xor

`eq` is high when bits differ — should use xnor.

Easy

Full-adder — fix the carry

Sum is right, carry-out is wrong. Patch the architecture.

Easy

Mux — default '1' instead of input

Returns '1' for sel=1 instead of b.

Easy

Mux — wrong default

sel=0 returns b instead of a.

Easy

Mux 2:1 — sel inverted

sel chooses the wrong input. Fix it.

Easy

NOR via AND

Author DeMorganized incorrectly.

Easy

Inverter that's a buffer

`y <= a` should be `not a`.

Easy

Parity using nand

Author used nand instead of xor.

Easy

Half-adder — sum & cout swapped

sum is on cout and vice-versa.

Easy

Adder — sign extension

Padding with zeros where signed extension was needed.

Medium

ALU — op missing

`xor` op decodes to zeros — fix the case.

Medium

Async reset wired sync

Process sensitivity list excludes reset.

Medium

BCD decoder — digit dropped

Digit 7 produces zeros.

Medium

Comparator — bad equal

`eq` is always 0.

Medium

Counter — reset ignored

Reset never zeroes the counter.

Medium

Divider by 8 — meant 4

Counter compare uses wrong constant.

Medium

Edge detector — falls instead of rises

Pulses on 1→0 transitions, not 0→1.

Medium

FSM — unreachable state

One transition guard never fires.

Medium

Gray code — two bits flip

Two bits flip on adjacent transitions.

Medium

Load register — wrong edge

Loads on falling edge instead of rising.

Medium

4:1 mux — sel only 1 bit

Top half of inputs is unreachable.

Medium

Shift register — wrong direction

Should shift left, shifts right.

Medium

T-FF ignores enable

Toggles every cycle regardless of t.

Medium

Up/down — dir ignored

Always counts up.

Medium

ALU — wrong overflow flag

Reads bit 6 instead of bit 7.

Hard

Arbiter — starves req3

Priority never rotates to req3.

Hard

Booth — wrong shift

Logical instead of arithmetic shift.

Hard

CORDIC — rotation reversed

Rotates clockwise instead of CCW.

Hard

CRC — wrong polynomial

Author used 0x07 instead of the spec 0x1D.

Hard

FIFO pointer — wrap off

Wrap drops one slot.

Hard

Hamming(7,4) — parity swap

Two parity bits are swapped.

Hard

Handshake — race condition

ack rises before req is stable.

Hard

LFSR — wrong taps

Sequence stays short — fix tap polynomial.

Hard

Manchester — half-bit swap

Encoder emits '10' for 0 and '01' for 1 (inverted).

Hard

Multiplier — wrong extension

Sign-extends an unsigned operand.

Hard

PWM — off-by-one

Duty cycle is 1 too short.

Hard

SPI — wrong sample edge

Samples on rising instead of falling.

Hard

Stack — pop off-by-one

Empty asserts one cycle late.

Hard

UART — start-bit miss

FSM samples start bit at wrong time.

Hard
03 · Fill the gap

Fill in the missing piece

The skeleton is wired; one block is missing. Implement it.

AND body — fill

Implement the single output assignment.

Easy

Tri-state buffer — fill

Output a when en=1, otherwise 'Z'.

Easy

Comparator (eq) — fill

Implement the equality comparison line.

Easy

4-bit counter — fill the gap

Skeleton is wired; write the single increment line.

Easy

Decoder Y0 — fill

Compute the y(0) line.

Easy

Half-adder — write cout only

sum is given; you write cout.

Easy

Half-adder — write sum only

cout is given; you write sum.

Easy

2:1 mux output — fill

Implement the y assignment.

Easy

NAND body — fill

Single output assignment.

Easy

NOR body — fill

Single output assignment.

Easy

NOT body — fill

Implement the inverter.

Easy

OR body — fill

Single output assignment.

Easy

Parity body — fill

Implement the parity expression.

Easy

XNOR body — fill

Single output assignment.

Easy

XOR body — fill

Single output assignment.

Easy

Adder carry — fill

Connect c1 between bit-0 and bit-1 adders.

Medium

BCD digit 5 — fill

Provide the 7-segment pattern for the digit 5.

Medium

Divider — toggle line

Toggle clk_out on counter overflow.

Medium

Comparator gt — fill

Implement the greater-than line.

Medium

Counter wrap — fill

Implement the wrap-around case.

Medium

Edge pulse — fill

Compute pulse from d_curr and d_prev.

Medium

FSM transition — fill

Pick the next state from current + input.

Medium

Gray-code next — fill

Compute next Gray value.

Medium

Load register — branch

Implement the load=1 branch.

Medium

4:1 mux block — fill

Implement the 4:1 mux selection.

Medium

Priority encoder default

Cover the all-zero input case.

Medium

Shift register — fill bit

Choose the bit shifted in (din vs '0').

Medium

T-FF toggle — fill

Compute next q given t and current q.

Medium

Toggle reg feedback — fill

Compute next q from current q when en=1.

Medium

Up/down — direction logic

Choose ±1 based on dir.

Medium

ALU shift unit — fill

Implement left shift by sh bits.

Hard

Arbiter grant rotation

Pick next grant in round-robin order.

Hard

Booth step — fill

Conditional add/sub based on Booth bits.

Hard

CORDIC step (x)

Implement x' = x + dir*y.

Hard

CRC register update

Implement the CRC step (xor + shift).

Hard

FIFO read pointer

Increment the read pointer when pop && !empty.

Hard

Hamming syndrome

Compute the 3-bit syndrome of a code word.

Hard

LFSR feedback tap

Compute the feedback bit.

Hard

Manchester transition

Emit half-bit pair for the input bit.

Hard

PWM comparator — fill

Compare counter against duty.

Hard

Round-robin token

Rotate the token left each cycle.

Hard

SPI edge select — fill

Sample on falling sclk only.

Hard

Stack pop — fill

Decrement sp on pop && !empty.

Hard

Traffic FSM table — fill

Implement the next-state table.

Hard

UART sample point

Pulse sample_now when bit-counter mid-bit.

Hard
An unhandled error has occurred. Reload 🗙