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 problemsBundle 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.
Literals, signed values and expression width
1 problemWrite 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.
Nets, variables and the combinational always
1 problemTell 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.
Reset, enable and priority
1 problemGive 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.
Register stages, observation and waveforms
1 problemChain 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.
Instances, hierarchy and parameters
1 problemPlace 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.
A state machine from a state table
2 problemsTurn 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.
- 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.
- 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 problemDeclare 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.
Testbench techniques
1 problemWrite 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.
Recording waveforms
1 problemChoose 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.
Design from a requirement
1 problemRead 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.