Verilog 1
Verilog 1
VERILOG
INTERVIEW QUESTION
Verilog Interview Questions &
Answers
3
Chapter 1
Introduction
This chapter contains 50 carefully curated Verilog interview questions with detailed so-
lutions. Each question is presented with a clear answer, example code, and practical pro
tips.
Code
wire a ;
reg b ;
assign a = b & c ;
Pro Tip
In SystemVerilog, prefer using logic which can replace both wire and reg.
5
Verilog Interview Guide Kittu Patel
Code
Pro Tip
Never mix blocking and non-blocking in the same always block.
Code
Pro Tip
In SystemVerilog, use always_comb for stricter checks and better readability.
Q4. What is the difference between initial and always blocks in Verilog?
Answer: - initial: Executes only once at the start of simulation. Often used
for testbench stimulus or initialization. - always: Executes repeatedly whenever
triggered by its sensitivity list. Used for hardware description.
6
Verilog Interview Guide Kittu Patel
Code
initial begin
clk = 0;
end
Pro Tip
Use initial only in testbenches; avoid it in synthesizable RTL.
//
//
Code
casez ( sel )
2 ’ b1 ?: out = a ; // ? means don ’ t care
2 ’ b01 : out = b ;
endcase
Pro Tip
Prefer casez for synthesis safety. Avoid casex to prevent unintended matches.
Q6. What are parameters in Verilog and why are they used?
Answer: Parameters are constants that make modules reusable and configurable
without rewriting code. They allow designers to define widths, delays, or functional
settings inside modules.
7
Verilog Interview Guide Kittu Patel
Code
endmodule
Pro Tip
Use parameters for design reusability. In SystemVerilog, localparam prevents over-
ride.
Code
fork
#5 a = 1;
#10 b = 1;
join // waits 10 time units
fork
#5 a = 1;
#10 b = 1;
join_any // resumes after 5 time units
Pro Tip
Avoid using fork-join in synthesizable RTL; it is only for testbenches.
8
Verilog Interview Guide Kittu Patel
Code
Pro Tip
In SystemVerilog, use always_comb for even stricter rules and better clarity.
Code
Pro Tip
Most flip-flops are designed with posedge clk; use negedge for special cases like
DDR.
Answer: Compiler directives are special instructions (starting with `) that control
simulation and compilation. Examples include: - d̀efine for macros - ìnclude for
including files - t̀imescale for setting time unit and precision
9
Verilog Interview Guide Kittu Patel
Code
‘define WIDTH 8
‘timescale 1 ns /1 ps
module top ;
reg [ ‘WIDTH -1:0] data ;
endmodule
Pro Tip
Use macros for global definitions, but prefer parameters for module-specific con-
stants.
Code
reg clk ;
initial begin
clk = 0;
#5 clk = 1;
#10 clk = 0;
end
Pro Tip
Use initial blocks only in testbenches, not in synthesizable RTL.
10
Verilog Interview Guide Kittu Patel
Code
initial begin
$display ( " Time =%0 t a =% b b =% b " , $time , a , b ) ;
$monitor ( " Monitor at %0 t : a =% b b =% b " , $time , a , b ) ;
end
Pro Tip
Use $monitor for debugging signal changes and $display for specific checkpoints.
Answer: t̀imescale defines the time unit and precision for simulation. Format:
t̀imescale <time_unit>/<time_precision>
- Time unit: base unit of delay - Time precision: accuracy of simulation time
Code
‘timescale 1 ns /1 ps
initial begin
#5 $display ( " 5 ns delay " ) ;
#0.1 $display ( " 0.1 ns = 100 ps delay " ) ;
end
Pro Tip
Always include ‘timescale at the top of simulation files for consistency.
//
//
11
Verilog Interview Guide Kittu Patel
Code
case ( sel )
2 ’ b00 : y = a ;
2 ’ b01 : y = b ;
default : y = 0;
endcase
Pro Tip
Avoid casex in synthesizable code since it can hide unknown states during simula-
tion.
Code
Pro Tip
Use parameters instead of hardcoding values to make designs flexible.
Q16. Explain the difference between generate and for loops in Verilog.
Answer: - for loop inside an always block executes during simulation (behav-
ioral). - generate-for loop replicates hardware structures during elaboration
(structural).
12
Verilog Interview Guide Kittu Patel
Code
genvar i ;
generate
for ( i =0; i <4; i = i +1) begin : gen_block
and g1 ( y [ i ] , a [ i ] , b [ i ]) ;
end
endgenerate
Pro Tip
Use generate for hardware replication and for for simulation logic.
Code
assign sum = a ^ b ;
assign carry = a & b ;
Pro Tip
Use continuous assignments for simple combinational logic instead of procedural
blocks.
Code
13
Verilog Interview Guide Kittu Patel
Pro Tip
Most flip-flops are triggered on posedge, but some designs use negedge for specific
timing requirements.
Code
always @ ( a or b or c )
y = a & b & c;
Pro Tip
Use @(*) for combinational logic to avoid missing signals.
Code
Pro Tip
14
Verilog Interview Guide Kittu Patel
Code
task display ;
input [7:0] d ;
$display ( " Value =% d " , d ) ;
endtask
Pro Tip
Use functions for combinational logic and tasks for simulation/testbench activities.
Code
initial begin
@ ( posedge reset ) ;
$display ( " Reset occurred " ) ;
end
Pro Tip
Event controls are widely used in testbenches to synchronize with signal changes.
15
Verilog Interview Guide Kittu Patel
Code
// Behavioral
always @ ( posedge clk )
if ( enable ) q <= d ;
// RTL
assign q_next = enable ? d : q ;
Pro Tip
Write RTL for synthesizable hardware, use behavioral for testbenches.
Code
Pro Tip
Use non-blocking assignments and proper synchronization to avoid race conditions.
16
Verilog Interview Guide Kittu Patel
Code
initial begin
clk = 0;
forever #5 clk = ~ clk ; // Toggle every 5 time units
end
Pro Tip
Never use delays in synthesizable RTL code—only use them in testbenches.
Code
initial begin
clk = 0; // Runs once
end
Pro Tip
Use always for synthesizable hardware; initial should be reserved for testbenches.
Code
initial begin
$display ( " Simulation start at %0 t " , $time ) ;
#100 $finish ;
end
17
Verilog Interview Guide Kittu Patel
Pro Tip
System tasks are not synthesizable; they are used only for verification.
Code
Pro Tip
Delays should be avoided in synthesizable RTL—keep them for testbenches.
Q29. What is the difference between posedge and negedge for resets?
Answer: - posedge reset: Active-high reset (triggered when reset goes 0→1). -
negedge reset: Active-low reset (triggered when reset goes 1→0). Both are used
for asynchronous reset in sequential logic.
Code
Pro Tip
18
Verilog Interview Guide Kittu Patel
Code
// Preferred method
counter #(. WIDTH (16) ) u1 (...) ;
Pro Tip
Always use parameter override during instantiation instead of defparam.
Answer: - Blocking delay (#): Suspends execution for a specific time. - Non-
blocking delay (## in SystemVerilog): Used for cycle-based delays in verification.
Code
initial begin
#5 a = 1; // Blocking delay
end
Pro Tip
In pure Verilog, only blocking delays are available. Use carefully in testbenches.
19
Verilog Interview Guide Kittu Patel
Code
Pro Tip
Q33. What is the difference between blocking assignment (=) and delay
control (#)?
Code
initial begin
#5 a = b ; // Assign after 5 time units
end
Pro Tip
Avoid delays in RTL. They are useful only in simulation.
20
Verilog Interview Guide Kittu Patel
Code
initial begin
a = 1;
b = 2;
end
initial fork
a = 1;
b = 2;
join
Pro Tip
Use fork-join in testbenches when you want parallel stimulus.
Code
‘define WIDTH 8
module counter ( input clk , output reg [ ‘WIDTH -1:0] q ) ;
...
endmodule
Pro Tip
21
Verilog Interview Guide Kittu Patel
Code
integer i ;
real r ;
time t ;
initial begin
i = 10;
r = 3.14;
t = $time ;
end
Pro Tip
Use integer for counters, time for measuring delays, and real only in testbenches.
Answer: UDPs allow designers to define custom logic functions at the gate level.
Two types: - Combinational UDP - Sequential UDP
Code
Pro Tip
UDPs are rarely used in modern RTL but are useful for library modeling.
Q38. What is the difference between posedge clk and @(posedge clk)?
Answer: - posedge clk: Used in sensitivity list of an always block. - @(posedge
clk): Explicit event control inside procedural code.
22
Verilog Interview Guide Kittu Patel
Code
initial begin
@ ( posedge clk ) ; // Wait for rising edge
$display ( " Clock edge detected " ) ;
end
Pro Tip
Use @(posedge clk) in testbenches, always @(posedge clk) in RTL.
Code
Pro Tip
Use assign for simple combinational logic; blocking assignment for procedural
modeling.
Code
23
Verilog Interview Guide Kittu Patel
Pro Tip
Always declare nets explicitly to avoid hidden bugs.
Code
Pro Tip
Q42. What are the main differences between Verilog and SystemVerilog?
Answer: - Verilog: Basic HDL, limited OOP support, less strict checks. - Sys-
temVerilog: Superset of Verilog with OOP, assertions, constrained random, better
testbench features.
Code
// Verilog
reg a ;
// SystemVerilog
logic a ;
Pro Tip
For RTL, Verilog is enough; for verification, SystemVerilog is preferred.
Answer: FSM (Finite State Machine) is a design model with states and transitions.
Two types: - Mealy (output depends on state + input) - Moore (output depends
only on state)
24
Verilog Interview Guide Kittu Patel
Code
Pro Tip
Use enumerated states for readability and debugging.
Code
‘timescale 1 ns /1 ps
// RTL sim runs fast , GLS verifies timing with SDF
Pro Tip
Run GLS for final sign-off before tape-out.
Answer: - Use non-blocking (<=) for state transitions and registers. - Use blocking
(=) for combinational next-state logic.
25
Verilog Interview Guide Kittu Patel
Code
Pro Tip
Follow the guideline: Non-blocking for sequential, blocking for combinational.
Code
Pro Tip
Avoid by using non-blocking assignments and proper synchronization.
Code
Pro Tip
Avoid tristates in FPGA design; use multiplexers instead.
26
Verilog Interview Guide Kittu Patel
Code
// RTL
assign y = a & b ;
// Structural
and g1 (y , a , b ) ;
Pro Tip
RTL is most widely used for synthesis; structural is used in library modeling.
Code
Pro Tip
Event-driven is precise; cycle-accurate is faster for large system simulation.
27
Verilog Interview Guide Kittu Patel
Code
// Synthesizable
always @ ( posedge clk ) q <= d ;
// Non - synthesizable
initial $display ( " Test " ) ;
Pro Tip
Keep RTL clean of non-synthesizable constructs to ensure portability.
Code
module d_ff (
input wire clk , reset , d ,
output reg q
);
always @ ( posedge clk or posedge reset ) begin
if ( reset )
q <= 1 ’ b0 ;
else
q <= d ;
end
endmodule
Pro Tip
28
Verilog Interview Guide Kittu Patel
Code
module jk_ff (
input wire clk , reset , j , k ,
output reg q
);
always @ ( posedge clk or posedge reset ) begin
if ( reset )
q <= 1 ’ b0 ;
else begin
case ({ j , k })
2 ’ b00 : q <= q ; // No change
2 ’ b01 : q <= 1 ’ b0 ; // Reset
2 ’ b10 : q <= 1 ’ b1 ; // Set
2 ’ b11 : q <= ~ q ; // Toggle
endcase
end
end
endmodule
Pro Tip
JK Flip-Flops are rarely used directly; D-FFs dominate in modern design.
29
Verilog Interview Guide Kittu Patel
Code
module t_ff (
input wire clk , reset , t ,
output reg q
);
always @ ( posedge clk or posedge reset ) begin
if ( reset )
q <= 1 ’ b0 ;
else if ( t )
q <= ~ q ;
end
endmodule
Pro Tip
T-FFs are useful in counter design.
Q54. Write Verilog code for a 4-bit Ripple Counter using T Flip-Flops.
Answer: Ripple counters are asynchronous counters where each flip-flop toggles
based on the previous one’s output.
Code
module ripple_counter (
input wire clk , reset ,
output [3:0] q
);
t_ff t0 ( clk , reset , 1 ’ b1 , q [0]) ;
t_ff t1 ( q [0] , reset , 1 ’ b1 , q [1]) ;
t_ff t2 ( q [1] , reset , 1 ’ b1 , q [2]) ;
t_ff t3 ( q [2] , reset , 1 ’ b1 , q [3]) ;
endmodule
Pro Tip
Ripple counters are simple but suffer from propagation delay. Use synchronous
counters for high-speed designs.
30
Verilog Interview Guide Kittu Patel
Code
module sync_counter (
input wire clk , reset ,
output reg [3:0] q
);
always @ ( posedge clk or posedge reset ) begin
if ( reset )
q <= 4 ’ b0000 ;
else
q <= q + 1;
end
endmodule
Pro Tip
31
Verilog Interview Guide Kittu Patel
Code
module mod10_counter (
input wire clk , reset ,
output reg [3:0] q
);
always @ ( posedge clk or posedge reset ) begin
if ( reset )
q <= 4 ’ b0000 ;
else if ( q == 4 ’ d9 )
q <= 4 ’ b0000 ;
else
q <= q + 1;
end
endmodule
Pro Tip
Use modulo counters in digital clocks and timers.
Pro Tip
Prefer Moore FSMs for stable outputs; Mealy FSMs are efficient but sensitive to
glitches.
Q58. Write Verilog code for a simple Moore FSM (sequence detector
for “101”).
Answer: This FSM outputs 1 whenever the sequence “101” is detected in the
input stream.
32
Verilog Interview Guide Kittu Patel
Code
module seq_detector (
input wire clk , reset , din ,
output reg dout
);
typedef enum reg [1:0] { S0 , S1 , S2 , S3 } state_t ;
state_t state , next_state ;
Pro Tip
Sequence detectors are common interview FSM coding problems.
33
Verilog Interview Guide Kittu Patel
Code
module shift_reg (
input wire clk , reset , d ,
output reg [3:0] q
);
always @ ( posedge clk or posedge reset ) begin
if ( reset )
q <= 4 ’ b0000 ;
else
q <= { q [2:0] , d }; // Shift left
end
endmodule
Pro Tip
Shift registers are widely used in UARTs and serial-to-parallel conversion.
Code
module dff_async_reset (
input wire clk , reset , d ,
output reg q
);
always @ ( posedge clk or posedge reset ) begin
if ( reset )
q <= 1 ’ b0 ;
else
q <= d ;
end
endmodule
Pro Tip
Always include reset logic in flip-flops for predictable hardware initialization.
34
Verilog Interview Guide Kittu Patel
Code
module dff_sync_reset (
input wire clk , reset , d ,
output reg q
);
always @ ( posedge clk ) begin
if ( reset )
q <= 1 ’ b0 ;
else
q <= d ;
end
endmodule
Pro Tip
Synchronous resets avoid asynchronous glitches but require the clock to be active.
Code
module up_counter (
input wire clk , reset ,
output reg [3:0] q
);
always @ ( posedge clk or posedge reset ) begin
if ( reset )
q <= 4 ’ b0000 ;
else
q <= q + 1;
end
endmodule
35
Verilog Interview Guide Kittu Patel
Pro Tip
Use up counters in address generation and event counting.
Code
module down_counter (
input wire clk , reset ,
output reg [3:0] q
);
always @ ( posedge clk or posedge reset ) begin
if ( reset )
q <= 4 ’ b1111 ;
else
q <= q - 1;
end
endmodule
Pro Tip
Down counters are useful in timers and event countdown circuits.
36
Verilog Interview Guide Kittu Patel
Code
module up_down_counter (
input wire clk , reset , dir ,
output reg [3:0] q
);
always @ ( posedge clk or posedge reset ) begin
if ( reset )
q <= 4 ’ b0000 ;
else if ( dir )
q <= q + 1;
else
q <= q - 1;
end
endmodule
Pro Tip
Add terminal count detection for designing Mod-N up-down counters.
Code
module ring_counter (
input wire clk , reset ,
output reg [3:0] q
);
always @ ( posedge clk or posedge reset ) begin
if ( reset )
q <= 4 ’ b0001 ;
else
q <= { q [2:0] , q [3]};
end
endmodule
Pro Tip
Ring counters are used in sequence generation and timing applications.
37
Verilog Interview Guide Kittu Patel
Answer: A Johnson counter (or twisted ring) shifts its inverted last bit into the
front.
Code
module johnson_counter (
input wire clk , reset ,
output reg [3:0] q
);
always @ ( posedge clk or posedge reset ) begin
if ( reset )
q <= 4 ’ b0000 ;
else
q <= {~ q [0] , q [3:1]};
end
endmodule
Pro Tip
Johnson counters generate 2N states with N flip-flops.
Q67. Write Verilog code for a Serial-In Serial-Out (SISO) Shift Register.
Answer: SISO registers shift data bit by bit through the chain of flip-flops.
38
Verilog Interview Guide Kittu Patel
Code
module siso_reg (
input wire clk , reset , d ,
output reg q
);
reg [3:0] shift ;
Pro Tip
SISO registers are useful in serial communication links.
Q68. Write Verilog code for a Serial-In Parallel-Out (SIPO) Shift Reg-
ister.
Answer: This register shifts data serially but provides parallel access.
Code
module sipo_reg (
input wire clk , reset , d ,
output reg [3:0] q
);
always @ ( posedge clk or posedge reset ) begin
if ( reset )
q <= 4 ’ b0000 ;
else
q <= { q [2:0] , d };
end
endmodule
39
Verilog Interview Guide Kittu Patel
Pro Tip
Used in UART receivers for parallel data recovery.
Q69. Write Verilog code for a Parallel-In Serial-Out (PISO) Shift Reg-
ister.
Answer: Loads parallel data and then shifts it serially.
Code
module piso_reg (
input wire clk , reset , load ,
input wire [3:0] din ,
output reg dout
);
reg [3:0] shift ;
always @ ( posedge clk or posedge reset ) begin
if ( reset )
shift <= 4 ’ b0000 ;
else if ( load )
shift <= din ;
else
shift <= {1 ’ b0 , shift [3:1]};
end
assign dout = shift [0];
endmodule
Pro Tip
PISO registers are useful for data serialization in communication protocols.
Answer: Directly loads parallel inputs and makes them available at outputs.
40
Verilog Interview Guide Kittu Patel
Code
module pipo_reg (
input wire clk , reset ,
input wire [3:0] din ,
output reg [3:0] q
);
always @ ( posedge clk or posedge reset ) begin
if ( reset )
q <= 4 ’ b0000 ;
else
q <= din ;
end
endmodule
Pro Tip
PIPO registers are the simplest form of registers used in CPUs.
41
Verilog Interview Guide Kittu Patel
Code
module t hr e e _o n e s_ d e te c t or (
input wire clk , reset , din ,
output reg dout
);
typedef enum reg [1:0] { S0 , S1 , S2 , S3 } state_t ;
state_t state , next_state ;
Pro Tip
FSM-based sequence detectors are standard digital design interview questions.
42
Verilog Interview Guide Kittu Patel
Code
module bin2gray (
input wire [3:0] bin ,
output wire [3:0] gray
);
assign gray = bin ^ ( bin >> 1) ;
endmodule
Pro Tip
Gray codes are widely used in rotary encoders and error reduction.
Code
module gray2bin (
input wire [3:0] gray ,
output reg [3:0] bin
);
integer i ;
always @ (*) begin
bin [3] = gray [3];
for ( i = 2; i >= 0; i = i - 1)
bin [ i ] = bin [ i +1] ^ gray [ i ];
end
endmodule
Pro Tip
Gray-Binary conversions are critical in asynchronous FIFO designs.
43
Verilog Interview Guide Kittu Patel
Code
module comparator4 (
input wire [3:0] a , b ,
output wire eq , gt , lt
);
assign eq = ( a == b ) ;
assign gt = ( a > b ) ;
assign lt = ( a < b ) ;
endmodule
Pro Tip
Comparators are fundamental building blocks in ALUs.
Answer: The encoder outputs the binary index of the highest-priority active input.
Code
44
Verilog Interview Guide Kittu Patel
Pro Tip
Priority encoders are used in interrupt handling circuits.
Answer: A JK flip-flop toggles its output when both inputs are high, otherwise behaves
like SR flip-flop with no invalid state.
45
Verilog Interview Guide Kittu Patel
JK Flip-Flop
module j k _ f f ( i n p u t j , k , c l k , output r e g q ) ;
always @( posedge c l k ) b e g i n
c a s e ({ j , k })
2 ’ b00 : q <= q ; // hold
2 ’ b01 : q <= 0 ; // r e s e t
2 ’ b10 : q <= 1 ; // s e t
2 ’ b11 : q <= ~q ; // t o g g l e
endcase
end
endmodule
Answer: - Synchronous counter: All flip-flops are triggered by the same clock, so
outputs change simultaneously. - Asynchronous counter: Clock is passed through
flip-flop outputs, causing propagation delay.
Answer: A Johnson counter feeds back the inverted output of the last flip-flop into the
first, generating 2n unique states.
46
Verilog Interview Guide Kittu Patel
Johnson Counter
2:1 Multiplexer
4:1 Multiplexer
47
Verilog Interview Guide Kittu Patel
Answer: - Moore FSM: Output depends only on state. - Mealy FSM: Output depends
on both state and input (can react faster).
Answer: This FSM outputs 1 whenever the sequence "101" is detected in serial input.
always @( ∗ ) b e g i n
case ( state )
S0 : next = i n ? S1 : S0 ;
S1 : next = i n ? S1 : S2 ;
S2 : next = i n ? S3 : S0 ;
S3 : next = i n ? S1 : S2 ;
endcase
end
always @( ∗ ) out = ( s t a t e == S3 ) ;
endmodule
48
Verilog Interview Guide Kittu Patel
always @( posedge c l k ) b e g i n
i f ( r s t ) q <= 0 ;
e l s e q <= d ;
end
3-to-8 Decoder
module d e c o d e r 3 t o 8 ( i n p u t [ 2 : 0 ] a , output r e g [ 7 : 0 ] y ) ;
always @( ∗ ) b e g i n
y = 8 ’ b0 ;
y [ a ] = 1;
end
endmodule
49
Verilog Interview Guide Kittu Patel
4-bit Comparator
module comp4 ( i n p u t [ 3 : 0 ] a , b ,
output l t , gt , eq ) ;
assign lt = (a < b );
a s s i g n gt = ( a > b ) ;
a s s i g n eq = ( a == b ) ;
endmodule
genvar i ;
generate
f o r ( i =0; i <8; i=i +1) b e g i n : and_gates
and g ( y [ i ] , a [ i ] , b [ i ] ) ;
end
endgenerate
module s h i f t _ r e g ( i n p u t c l k , r s t , din ,
output r e g [ 7 : 0 ] q ) ;
always @( posedge c l k o r posedge r s t ) b e g i n
i f ( r s t ) q <= 0 ;
e l s e q <= {q [ 6 : 0 ] , d in } ;
end
endmodule
50
Verilog Interview Guide Kittu Patel
Answer: - Blocking delay (‘10 a=1;‘) halts execution for 10 time units. - Non-blocking
delay is not synthesizable and is mainly used in testbenches.
module r i n g _ c o u n t e r ( i n p u t c l k , r s t ,
output r e g [ 3 : 0 ] q ) ;
always @( posedge c l k o r posedge r s t ) b e g i n
i f ( r s t ) q <= 4 ’ b0001 ;
e l s e q <= {q [ 2 : 0 ] , q [ 3 ] } ;
end
endmodule
Answer: Metastability occurs when setup or hold times are violated, causing unpre-
dictable output. Mitigation: Use synchronizers (two-stage flip-flops) for async signals.
Answer: Gray code ensures only one bit changes between successive states.
51
Verilog Interview Guide Kittu Patel
module gray_counter ( i n p u t c l k , r s t ,
output r e g [ 3 : 0 ] q ) ;
always @( posedge c l k o r posedge r s t ) b e g i n
i f ( r s t ) q <= 0 ;
e l s e q <= ( q >> 1 ) ^ q ;
end
endmodule
Priority Encoder
module p r i o r i t y _ e n c ( i n p u t [ 3 : 0 ] d , output r e g [ 1 : 0 ] y ) ;
always @( ∗ ) b e g i n
casex (d)
4 ’ b1xxx : y = 2 ’ b11 ;
4 ’ b01xx : y = 2 ’ b10 ;
4 ’ b001x : y = 2 ’ b01 ;
4 ’ b0001 : y = 2 ’ b00 ;
d e f a u l t : y = 2 ’ b00 ;
endcase
end
endmodule
52
Verilog Interview Guide Kittu Patel
SR Flip-Flop
module s r _ f f ( i n p u t s , r , c l k , output r e g q ) ;
always @( posedge c l k ) b e g i n
i f ( s & ~ r ) q <= 1 ;
e l s e i f (~ s & r ) q <= 0 ;
e l s e i f ( s & r ) q <= 1 ’ bx ; // i n v a l i d
end
endmodule
T Flip-Flop
module t _ f f ( i n p u t t , c l k , output r e g q ) ;
always @( posedge c l k ) b e g i n
i f ( t ) q <= ~q ;
end
endmodule
Answer:
53
Verilog Interview Guide Kittu Patel
module b i n 2 g r a y ( i n p u t [ 3 : 0 ] b , output [ 3 : 0 ] g ) ;
a s s i g n g = ( b >> 1 ) ^ b ;
endmodule
module g r a y 2 b i n ( i n p u t [ 3 : 0 ] g , output r e g [ 3 : 0 ] b ) ;
always @( ∗ ) b e g i n
b[3] = g [3];
b[2] = g[3] ^ g [2];
b[1] = b[2] ^ g [1];
b[0] = b[1] ^ g [0];
end
endmodule
54
Summary
This document has compiled more than 100 carefully curated Verilog interview questions
with comprehensive answers, code examples, and practical insights. It covers a wide
spectrum of topics including basic Verilog constructs, modeling styles, flip-flops, counters,
FSMs, and hardware design practices.
The intention of this guide is not just to prepare you for interviews, but also to
strengthen your fundamentals in Verilog and digital design. If you revise these questions
thoroughly, you will gain the confidence to approach real-world interviews with clarity
and precision.
55
Acknowledgment & Thanks
Thank you for taking the time to go through this guide. I truly hope it helps you in
cracking interviews and building a strong career in the VLSI industry.
If at any point you face difficulties in understanding concepts, or if you are looking for
a mock interview session to simulate real interview scenarios and improve your confidence,
feel free to reach out.
I will be more than happy to guide you personally so that you can unlock better career
opportunities.
—
57
Contact Information
For further guidance, counseling, or mock interview sessions, please contact me at:
• Email: [email protected]
Stay consistent, stay curious, and keep practicing. Your dedication today will shape
your future in the semiconductor industry.
59