FREE — INTERVIEW QUESTIONS

Verilog interview questions, with worked answers, code and output puzzles

90+ free Verilog questions on data types, widths and signedness, blocking and non-blocking assignments, the event queue, case statements, generate, FSMs, memories, synthesis and testbenches. Includes 18 worked answers with code, 8 predict-the-output puzzles, one simulation time step traced region by region and a Verilog literal decoder.

550+ Verilog Interview Questions ebook cover
VERILOG EBOOK · 580 QUESTIONS · 27 CHAPTERS

Get the complete Verilog question bank, fully answered

580 questions with interview-ready answers and tips, 20 coding exercises with verified solutions, 25 predict-the-output puzzles and 30 debugging scenarios.

INSTANT PDF DOWNLOAD · 8 FREE PREVIEW PAGES
See the ebook

Verilog questions check whether you can see the hardware behind the code. They open most RTL design, verification and FPGA interviews, and they decide many fresher interviews on their own, because a short snippet quickly shows whether a candidate understands widths, assignments and timing or has only memorised syntax.

Strong answers say what the code becomes in hardware, what width it's evaluated at and when the simulator updates it. Start with the rules sheet and the decoder, skim the 50 questions by topic, then try each worked answer and puzzle before you open it. The code examples page has complete modules you can simulate.

HOW IT'S ASKED

Three levels of a Verilog interview

LEVEL 1

Language rules

Nets and variables, the four logic values, literals, widths, signedness and operators. Expect "what width is this?" and "what does this print?"

LEVEL 2

Code it live

A flop with reset, a counter, an FSM, a small memory or a pulse generator, written on a whiteboard or shared editor, with no latches and the right assignment types.

LEVEL 3

Simulation versus silicon

The event queue, races, X-propagation, simulation–synthesis mismatches and gate-level surprises: "it passed RTL simulation, so why doesn't it work?"

HOW TO ANSWER

Six habits of strong Verilog answers

01

Say what it becomes

Flip-flop, latch, mux or adder. Naming the hardware first shows you write RTL as a circuit description, not as a program.

02

State the width

Before giving a value, say how many bits the expression is evaluated at. Most trick questions are width questions in disguise.

03

One variable, one style

<= in clocked blocks, = in combinational blocks, and each variable assigned in only one block.

04

Cover every path

Default-assign outputs in combinational blocks, reset every register that needs a known value, and give every case a default.

05

Think in time steps

When an answer depends on ordering, walk through Active, NBA and Monitor. It turns guesswork into a short, confident explanation.

06

Separate simulation from synthesis

Delays, initial blocks, sensitivity lists and $display behave differently, or vanish, once the code becomes gates.

RULES SHEET

The Verilog rules interviewers expect you to quote

IEEE 1364-2005 Verilog. Most also hold in SystemVerilog, which adds types such as logic and always_ff on top.

FOUR STATES0, 1, X, Z · undriven net = Z · unassigned variable = XMost operators turn a Z input into X.
LITERALS<size>'<s><base><digits> · 8'hA5 · 4'sb1010 · 6'o17Unsized literals are at least 32 bits. A plain decimal like 12 is signed; 'd12 is not.
PADDINGfewer digits than size: zero-fill on the left · leftmost digit x or z: x- or z-fillExtra digits are truncated from the left, usually with only a warning.
WIDTH RULEevaluate at the widest operand, including the assignment targetConcatenations, comparison operands and system-task arguments keep their own width.
SIGN RULEone unsigned operand → the whole expression is unsignedPart-selects and concatenations are unsigned, even of signed variables.
ASSIGNMENTSclocked always → <= · always @* → = · nets → assignNever mix = and <= on the same variable.
LATCHalways @* leaves a variable unassigned on some path → latchDefault-assign every output at the top of the block.
CASE FAMILYcase: exact · casez: z and ? are don't-care · casex: x and z are don't-care
EQUALITY== can return X · === compares X and Z literally (testbench only)An if with an X condition takes the else branch.
SHIFTS<< >> logical · >>> arithmetic only if the operand is signed
TIME STEPActive → Inactive (#0) → NBA (<= updates) → Monitor ($strobe, $monitor)Any new event sends the simulator back to Active: a new delta cycle.
TRY IT

Verilog literal decoder

Type a literal the way you'd write it in code. See its width, signedness, bits and value, including padding, truncation and x/z handling.

WIDTH–
TYPE–
AS UNSIGNED–
AS SIGNED (2'S COMP.)–
BINARY–
HEX–

 

WHICH CONSTRUCT WHERE

Assignments and blocks, compared

"Where would you use this?" and "what does it synthesise to?" come up for every one of these. Getting the update timing right answers half the follow-ups.

CONSTRUCTWHERE IT BELONGSWHEN IT UPDATESWHAT SYNTHESIS BUILDSCLASSIC MISTAKE
assignOutside procedural blocks, driving a netWhenever any right-hand operand changesCombinational logicUsing it to drive a variable declared reg
= in always @*Combinational always blocksImmediately, in the Active regionCombinational logicLeaving a path unassigned, which builds a latch
<= in always @(posedge clk)Clocked always blocksRight side read now, update applied in the NBA regionFlip-flopsExpecting the new value on the next line
initialTestbenches, simulation modelsOnce, at time 0Ignored by ASIC synthesis; FPGA tools may use it for power-up valuesUsing it instead of a reset
functionInside expressionsIn zero time, returns one valueCombinational logic, inlinedAdding delays or event controls, which are illegal
taskCalled as a statementCan consume time with # or @Inlined logic only if it has no timingExpecting a task that waits for a clock to synthesise
BROWSE BY TOPIC

50 Verilog interview questions across 10 topics

A sample of what Verilog interviewers ask most. The 580-question ebook goes much deeper on each topic and answers every question.

Language Basics & Data Types

The first five minutes of a Verilog round.

  • Why does Verilog need both nets and variables, when software languages manage with variables alone?
  • A 4-bit reg is never assigned before the first clock edge. What does it hold, and why should that worry you?
  • When would you declare a net as wand or wor instead of wire?
  • How do integer and reg [31:0] differ in simulation, and in what synthesis builds?
  • Can a port declared output reg also be driven by a continuous assignment inside the module?

Widths, Signedness & Operators

Where most silent bugs come from.

  • Two 8-bit inputs are added into a 9-bit result. Under which coding styles is the carry kept, and when is it lost?
  • Why can $signed(a) > b still compare unsigned values?
  • What is the difference between !, ~ and ~| applied to a 4-bit vector?
  • When does the conditional operator ?: return a mix of known and unknown bits?
  • a is 3 bits and b is 5 bits. What are the widths of {a, b} and of a + b, and why do they differ?

Modules, Ports & Parameters

Building hierarchy that others can reuse.

  • Why is defparam discouraged, and what replaced it?
  • Why do large designs connect ports by name rather than by position?
  • What bug does `default_nettype none catch at compile time?
  • How would you size a counter so that it can hold any value up to a parameter DEPTH?
  • What problems come from leaving an input port floating at the top level of a block?

Procedural Blocks & Assignments

Where hardware intent meets simulator behaviour.

  • An always @* block calls a function that reads a module-level signal not passed as an argument. Why might the block miss changes to it?
  • Why do guidelines ask for <= in clocked blocks even when = appears to work?
  • Why does always @(posedge clk or rst) fail to model an asynchronous reset properly?
  • How can an initial block appear in RTL that targets an FPGA, but not in ASIC RTL?
  • What changes in hardware when rst moves from inside an if in a clocked block into its sensitivity list?

Simulation Time & Races

How the simulator orders events inside one time step.

  • Explain a delta cycle in one sentence, then give an example.
  • Why can $display placed after a non-blocking assignment print the old value?
  • Write two initial blocks that race, and say how you would remove the race.
  • Why does $monitor print at most once per time step even if a signal toggles twice in it?
  • What does `timescale 1ns/1ps mean, and what breaks if files use different time scales?

Case, Loops & Generate

Constructs that repeat or select hardware.

  • In a casez, what is the difference between an item written 4'b1??? and one written 4'b1xxx?
  • Two items of a case statement overlap. Which one wins in simulation, and what does synthesis build?
  • A for loop inside an always block is synthesisable. What hardware does it actually produce?
  • When do you need a generate if rather than an ordinary if inside an always block?
  • How do you code a 16-way select so it builds a balanced mux instead of a long priority chain?

Tasks, Functions & System Tasks

Reusable code and the simulator's toolbox.

  • Why can a function not contain # delays or wait for a clock edge?
  • What changes when a task or function is declared automatic?
  • How do you get a random number between 0 and 9 in a plain Verilog testbench, and why is $random % 10 not enough?
  • What does $readmemh expect in its file, and what is left in memory locations the file doesn't cover?
  • How do you print the time and the hierarchical instance name in a message?

RTL Patterns: FSMs, Counters & FIFOs

The blocks you'll be asked to write on the spot.

  • Why do many teams split an FSM into a state register block and a next-state block?
  • Binary, Gray or one-hot: which state encoding would you pick on an FPGA, and why?
  • How do you make sure an FSM recovers if it ever lands in an unused state code?
  • Read and write pointers of a FIFO are equal. How does the design know whether it is full or empty?
  • How would you build a two-digit BCD counter, so that 09 is followed by 10 and 99 by 00?

Synthesis & Coding Style

What survives the trip from RTL to gates.

  • What happens to an initial block, a #5 delay and a $display when RTL goes through ASIC synthesis?
  • A case on a 2-bit selector lists all four values, yet lint still reports a latch. How can that happen?
  • Why is assign gclk = clk & en; a bad way to gate a clock?
  • How should you write a memory so that synthesis maps it to block RAM instead of flip-flops?
  • When does synthesis merge or remove registers you wrote, and how do you find out?

Testbenches & Debug

Proving the RTL works, and finding out why it doesn't.

  • How would you count errors in a testbench and print one clear PASS or FAIL line at the end?
  • How do you apply every input combination to a 4-input combinational block in a loop and check each one?
  • When should a testbench call $finish, and when $stop?
  • How do you check that a DUT output stays stable for a whole cycle, not just at the sampling edge?
  • Gate-level simulation shows X on an output that was clean in RTL. Where do you look first?

These are samples. The full bank is six times larger.

580 questions in 27 chapters, all answered: 20 coding exercises with verified solutions, 25 output puzzles, 30 debugging scenarios, plus GLS and SDF, lint and a 40-question rapid-fire round.

See the full question bank
P1 · PART-SELECTSBEGINNERWhat does this print?reg [15:0] data = 16'hBEEF; initial $display("%h %h %h", data[15 -: 4], data[4 +: 8], data[11:8]);Show answer ↓
Output: b ee e

data[15 -: 4] = data[15:12] = 4'hb
data[4 +: 8]  = data[11:4]  = 8'hee
data[11:8]               = 4'he

Note: -: counts down from the start bit and +: counts up. The width must be a constant, but the start can be a variable, which is why indexed part-selects are used for sliding windows.

P2 · REAL TO INTEGERINTERMEDIATEWhat does this print?integer i, j, k; initial begin i = 2.5; j = -2.5; k = 7 / 2; $display("%0d %0d %0d", i, j, k); endShow answer ↓
Output: 3 -3 3

real -> integer rounds to nearest, ties away from zero
 2.5 -> 3,  -2.5 -> -3
7 / 2 is integer division: truncates to 3

Note: assigning a real to an integer rounds; dividing two integers truncates. Mixing the two in one calculation is a common source of off-by-one results.

P3 · REPEAT COUNTBEGINNERWhat does this print?integer n, cnt; initial begin n = 3; cnt = 0; repeat (n) begin n = n + 1; cnt = cnt + 1; end $display("%0d %0d", cnt, n); endShow answer ↓
Output: 3 6

repeat (n) evaluates n once, when the loop starts.
Changing n inside the loop doesn't change the count.

Note: a while loop would re-test the condition each time; repeat doesn't.

P4 · X SELECT IN ?:INTERMEDIATEsel is never assigned. What is y?reg sel; reg [3:0] y; initial begin #1 y = sel ? 4'b1100 : 4'b1010; $display("%b", y); endShow answer ↓
Output: 1xx0

With an X select, ?: compares both options bit by bit:
  1100
  1010
  ----
  1xx0   equal bits kept, different bits become x

Note: an if with an X condition would have picked the else branch and printed 1010. The conditional operator is more pessimistic, and closer to what the hardware might do.

P5 · %h WITH UNKNOWNSINTERMEDIATEWhat does this print?reg [7:0] v; initial begin v = 8'b1010_xxxx; $display("%h", v); v = 8'b1010_x0x0; $display("%h", v); endShow answer ↓
Output:
ax
aX

Lowercase x: every bit of that hex digit is x.
Uppercase X: only some bits of the digit are x.

Note: the same rule applies to z and Z. When a hex dump shows a capital X, switch to %b to see which bits are unknown.

P6 · POSEDGE ON A VECTORADVANCEDHow many times does each always block run?reg [3:0] a; // starts at x integer pos = 0, any = 0; always @(posedge a) pos = pos + 1; always @(a) any = any + 1; initial begin #1 a = 4'b0001; #1 a = 4'b0010; #1 a = 4'b0011; #1 $display("%0d %0d", pos, any); endShow answer ↓
Output: 2 3

posedge on a vector looks only at the LSB:
  xxxx -> 0001 : LSB x -> 1  posedge (x->1 counts)
  0001 -> 0010 : LSB 1 -> 0  no posedge
  0010 -> 0011 : LSB 0 -> 1  posedge
@(a) fires on any change: 3 times

Note: transitions from x or z to 1, and from 0 to x or z, count as a posedge. Edge events on multi-bit signals are almost always a bug; write posedge a[0] if that's what you mean.

P7 · wait VERSUS @INTERMEDIATEWhat is printed, and at what times?reg flag; initial begin flag = 0; #5 flag = 1; #15 flag = 0; end initial begin #10; wait (flag) $display("wait done at %0t", $time); @(flag) $display("@ done at %0t", $time); endShow answer ↓
Output:
wait done at 10
@ done at 20

wait (flag): flag is already 1 at time 10, so it continues at once.
@(flag): waits for the next change, which is 1 -> 0 at time 20.

Note: wait is level-sensitive and @ is edge-sensitive. Using @ on a condition that may already be true is a classic testbench hang.

P8 · PARAMETER OVERRIDEBEGINNERWhat does each instance print?module m #(parameter W = 4); localparam MAX = (1 << W) - 1; initial $display("%m %0d", MAX); endmodule module top; m #(.W(6)) u1(); m u2(); endmoduleShow answer ↓
Output (order may vary):
top.u1 63
top.u2 15

localparam MAX is recomputed from each instance's W.

Note: the order of the two lines isn't defined, since the initial blocks run in an unspecified order. Trying m #(.MAX(7)) is a compile error: a localparam can't be overridden.

1 · ACTIVE blocking =, assign, RHS of <=, $display 2 · INACTIVE statements delayed by #0 3 · NBA every pending <= update is applied 4 · MONITOR $strobe and $monitor print settled values no events left: time advances updates wake more blocks: new delta cycle, same sim time
Active regionNon-blocking updatesDelta loop
always @(posedge clk) q1 <= d;
always @(posedge clk) q2 <= q1;
always @*             y  = q1 ^ q2;
  1. The clock rises (Active). Both clocked blocks wake up and read their right-hand sides: d and the old q1. Which block runs first isn't defined, and it doesn't matter, because neither changes anything yet.
  2. Updates are queued, not applied. q1 ← d and q2 ← old q1 wait in the NBA queue. Any $display in these blocks prints the old values.
  3. Inactive. Statements delayed by #0 would run here. Clean RTL has none.
  4. NBA. Both updates are applied together, so q1 and q2 change at once, just like two flops sharing a clock.
  5. A new delta cycle. The changes wake always @*, so the simulator returns to Active and recomputes y, still at the same simulation time.
  6. Monitor. With nothing left to do, $strobe and $monitor print the settled values, and simulation time moves forward.
Why does this ordering make flip-flop models race-free?

Every clocked block reads its inputs in the Active region before any register changes in the NBA region. So the result doesn't depend on which block the simulator happens to run first, which is the property real flops sharing a clock have.

What changes if both clocked blocks use = instead?

If the q1 block runs first, q1 updates immediately and the q2 block copies the new value, so the two-stage pipeline collapses into one. If the q2 block runs first, it works. The order is up to the simulator, so this is a genuine race, and two tools can disagree.

Where do $display and $strobe print in this step?

$display runs in the Active region with the statement that calls it, so after a <= it shows the old value. $strobe waits until the end of the time step and shows the settled value. $monitor also prints at the end, and only if a watched value changed.

Does SystemVerilog use the same regions?

For RTL, yes: Active, Inactive and NBA work the same way. SystemVerilog adds regions around them, such as Preponed, where assertions sample values, and Observed and Reactive, used by assertions and testbench programs. The SystemVerilog questions page and the Verilog ebook both go further into scheduling and races.

What does data[15 -: 4] select?

Bits 15 down to 12.

What does an undeclared name in a port connection become?

An implicit 1-bit wire, unless `default_nettype none is set.

Which keyword makes a module constant that a parent can't override?

localparam.

How many times does repeat (n) read n?

Once, when the loop starts.

!4'b0100?

1'b0: any nonzero value is true.

~4'b0100?

4'b1011.

1'b1 & 1'bz?

x.

1'b0 & 1'bx?

0: a 0 forces AND low.

1'b1 | 1'bx?

1: a 1 forces OR high.

4'b1010 & 4'b0110?

4'b0010.

What does $random return?

A signed 32-bit integer.

Format specifier for the current instance's path?

%m.

RTL value of a flop that has no reset, before its first clocked assignment?

X.

Width of the result of a == b?

1 bit.

What does `include do?

Pastes the named file's text in place before compiling.

Largest value an 8-bit signed reg can hold?

127.

What does 4'b10x1 mean?

A 4-bit value whose bit 1 is unknown.

Real-to-integer conversion: round or truncate?

Round to nearest, ties away from zero.

Is wait (cond) level- or edge-sensitive?

Level-sensitive.

Does `timescale affect synthesis?

No. It only sets simulation time units and precision.

COMMON MISTAKES

What costs candidates the most in Verilog rounds

×

Mixing = and <= in one clocked block

It's legal, but the result depends on statement order and often doesn't match the flops you meant. Use non-blocking for every clocked assignment.

×

Combinational blocks with a missing path

An if without else or a case without default in always @* infers a latch. Assign a default to every output at the top of the block.

×

Ignoring widths

Silent truncation, lost carries and zero-extension cause most "works for small numbers" bugs. Say the width before you say the value.

×

Assuming signed arithmetic

One unsigned operand makes the whole expression unsigned, and part-selects are always unsigned. Check every operand, not just the declaration.

×

Testbench habits in RTL

# delays, initial blocks used as reset, and === all simulate fine and then vanish or break in synthesis.

×

Letting X hide

An if on an X condition quietly takes the else branch, and casex treats X as a wildcard. Find the source of every X rather than coding around it.

QUICK FAQ

Before you start preparing

Is Verilog still asked if the company uses SystemVerilog?

Yes. SystemVerilog is a superset of Verilog, so design interviews still start with Verilog rules: assignments, widths, the event queue, latches and synthesis. Verification interviews then add classes, constraints and assertions on top, which the SystemVerilog questions cover.

Verilog or VHDL: which should I prepare for VLSI interviews?

For most semiconductor design and verification roles in India and the US, Verilog and SystemVerilog are far more common. VHDL still appears in some FPGA, defence and European companies, so check the job description.

Which topics should a fresher prepare first?

Data types and the four logic values, widths and signedness, blocking versus non-blocking, always @* and latches, case statements, a flip-flop with reset, a counter, an FSM and a basic testbench. Then the event queue and simulation–synthesis differences.

How much live coding should I expect?

Usually one or two small blocks: a counter, an edge detector, an FSM, a FIFO or a clock divider. Interviewers watch for clean resets, correct assignment types, no latches and sensible widths more than for clever tricks.

Which simulator should I practise on?

Any one you can run every day. Icarus Verilog and Verilator are free, EDA Playground runs in a browser, and the free editions of FPGA vendor simulators work well. What matters is typing the code and checking your prediction against the output.

How is this different from the RTL design round?

The Verilog round tests the language and how the simulator runs it. The RTL design round uses the language to build blocks such as FIFOs, arbiters and pipelines, and asks about timing, area and clock domain crossing.

Want to be tested on these live?

Book a 1:1 mock interview with a mentor working in this exact domain.

Book a mock interview