Skip to content
code0.HDL

Verilog Practice

Build fluency with short Verilog problems. Edit the module, run its testbench, then submit your solution.

Your drafts and solved problems stay in this browser.

Jump to a chapter

Vectors, bit selects and operators

2 problems

Bundle bits into a vector, pull ranges out of it, join pieces with braces, and learn what each operator family builds and how wide its result is, from bitwise, logical and reduction operators to arithmetic, shifts, comparisons and precedence, before rearranging a byte in Practice.

  1. 01ImplementationSwap the halves of a byteRoute the high and low 4-bit halves of an 8-bit vector to opposite halves of the output.
  2. 02VerificationMerge bytes through a maskFind why a masked byte merge loses the upper bits of the new value and correct it.

Literals, signed values and expression width

1 problem

Write sized literals, know that an unsized one is at least 32 bits, read one bit pattern as signed or unsigned, and give an addition a target wide enough to keep its carry.

  1. 04ImplementationKeep the carry out of an adderMake a 4-bit adder produce its full 5-bit sum instead of dropping the carry.

Nets, variables and the combinational always

1 problem

Tell nets from variables, write a multiplexer twice, as an assign with ?: and as an always @* with case, see why every path must assign the output, and use blocking = inside combinational blocks.

  1. 03ImplementationSelect one of four operationsDesign a combinational block that applies AND, OR, XOR or NOR to two 4-bit inputs according to a 2-bit select.

Reset, enable and priority

1 problem

Give a register a synchronous reset and an enable, order the if/else chain so reset wins, and make a counter wrap where the requirement says rather than where the width runs out.

  1. 06ImplementationWrap a counter after nineMake a clocked counter wrap from 9 back to 0 while keeping its synchronous reset.

Register stages, observation and waveforms

1 problem

Chain registers into stages, learn what a testbench sees at the edge, after #1, with $strobe and in a waveform, start a VCD recording with $dumpfile and $dumpvars, give its times a unit with `timescale, and build a rising-edge detector whose pulse is exactly one cycle wide.

  1. 09ImplementationTurn a level into a one-cycle pulseMake a registered detector raise its output for exactly one clock cycle after each rising input, and confirm the width in the waveform.

Instances, hierarchy and parameters

1 problem

Place a module inside another as an instance, connect its ports by name, override a parameter per instance, run internal nets between instances, read a four-bit ripple-carry adder as a hierarchy, and recognize the elaboration errors and silent miswirings a connection list can hide.

  1. 05VerificationWire two half adders into a full adderFind the miswired port connection that makes a full adder ignore one input and correct it.

A state machine from a state table

2 problems

Turn a state table into a state register, a next-state case and output logic, run a two-state rise detector and check its trace and waveform against the table, repair a broken transition, and design a three-state machine yourself.

  1. 11VerificationFind the broken transition in a state machineA two-state rise detector reports only the first rise. Compare its trace with the state table, find the wrong transition, and fix it.
  2. 12ImplementationDesign a three-state detector from its contractWrite the state table, then the state register, next-state logic and Moore output of a machine that raises seen after two 1s in a row.

Memories and FIFOs

1 problem

Declare a memory as an array of registers, write it at the edge and read it asynchronously or through a register with one cycle of latency, then build a parameterized synchronous FIFO whose count, full and empty decide which pushes and pops take effect.

  1. 13ImplementationMake a FIFO track how full it isGive a synchronous FIFO a correct count, full and empty for positive WIDTH and DEPTH from 1 to 16, ignoring pushes when full and pops when empty.

Testbench techniques

1 problem

Write a testbench with reg inputs, wire outputs and a dut instance, make time pass with # delays, a clock and event controls, then package stimulus in a task, compare against a model with !==, and end a failing or hanging run with $fatal.

  1. 08VerificationLet reset win over enableFind why an enabled counter ignores reset while it is idle and correct the priority.

Recording waveforms

1 problem

Choose which instances a VCD records with $dumpvars scopes and depths, read a waveform whose scopes skip a level, and recognize the mistakes that leave a recording empty, late, too shallow, off by a rounded delay, or missing an unnamed value.

  1. 10VerificationFind the missing stage in a delay lineUse the waveform to find why a two-stage delay line passes its input through one cycle early, and correct the register updates.

Design from a requirement

1 problem

Read a requirement into ports, widths, a select mapping, a priority order, a sampling time and boundary cases, predict the counter contract cycle by cycle, then write both checkpoint designs on your own.

  1. 07ImplementationA counter with clear and enableDesign a 4-bit counter whose synchronous clear wins over enable, counts modulo 16, and holds otherwise.