Professional Documents
Culture Documents
INTRODUCTION TO VERILOG
TOPICS TO BE COVERED
• Lexical conventions
• Data types
• Modules and ports
• Gate level modeling
Lexical conventions
endmodule
Components of a module
• Verilog allows multiple modules to be defined
in a single file.
• Modules can be defined in any order in the
file.
Example – SR latch
Verilog Code
// port declarations
output Q,Qbar;
input Sbar,Rbar;
Verilog Code…
//endmodule statement
endmodule
• All parts except module, module name and
endmodule are optional.
Ports
// Port declarations
output out;
input i0,i1,i2,i3;
input sel1,sel0;
// Gate instantiations
not (s1n,sel1);
not (s0n,sel0);
// and gate instantiations
and (y0,i0,s1n,s0n);
and (y1,i1,s1n,sel0);
and (y2,i2,sel1,s0n);
and (y3,i3,sel1,sel0);
// or gate instantiation
or (out,y0,y1,y2,y3);
endmodule
Stimulus or Test Bench for MUX
Stimulus code for MUX
//stimulus module
module stimulus;
begin
IN0 = 1; IN1 = 0; IN2 = 1; IN3 = 0;
$display(“IN0 = %b, IN1 = %b, IN2 = %b, IN3 = %b\n”, IN0, IN1, IN2, IN3);
S1 = 0; S0 = 0;
$display(“S1 = %b, S0 = %b,Z = %b\n”, S1, S0,Z);
S1 = 0; S0 = 1;
$display(“S1 = %b, S0 = %b,Z = %b\n”, S1, S0,Z);
S1 = 1; S0 = 0;
$display(“S1 = %b, S0 = %b,Z = %b\n”, S1, S0,Z);
S1 = 1; S0 = 1;
$display(“S1 = %b, S0 = %b,Z = %b\n”, S1, S0,Z);
end
endmodule