Hardware Description Language: - Tool For Specifying Hardware Circuits Types of HDL: - VHDL - Verilog
Hardware Description Language: - Tool For Specifying Hardware Circuits Types of HDL: - VHDL - Verilog
Types of HDL:
• VHDL
• Verilog
Levels of description
• Switch level
• Gate level
• Data flow level
• Behavioral level
Verilog Keywords & Constructs
• Keywords are lower case
• module – fundamental building block for Verilog
designs
– Used to construct design hierarchy
– Cannot be nested
• endmodule – ends a module – not a statement
=> no “;”
• Module Declaration
– module module_name (module_port, module_port, …);
– Example: module full_adder (A, B, c_in,
c_out, S);
Verilog Keywords & Constructs
• Input Declaration
– Scalar
• input list of input identifiers;
• Example: input A, B, c_in;
– Vector
• input[range] list of input identifiers;
• Example: input[15:0] A, B, data;
• Output Declaration
– Scalar Example: output c_out, OV, MINUS;
– Vector Example: output[7:0] ACC, REG_IN, data_out;
Basic structure of a Verilog module
Module module_name(list of ports);
input/output port declarations
Local net declarations
Parallel statements
endmodule
Verilog Keywords & Constructs
• Primitive Gates
– buf, not, and, or, nand, nor, xor, xnor
– Syntax: gate_operator instance_identifier (output,
input_1, input_2, …)
– Examples:
and A1 (F, A, B); //F = A B
or O1 (w, a, b, c)
O2 (x, b, c, d, e); //w=a+b+c,x=b+c+d+e
Nets
• Nets represent physical connections between hardware
elements
• Declared with the keyword wire
• Used to connect instantiated modules
• Must be continuously driven with a value
• Ex. wire b, c;
– Do not hold their value
– Take their value from a driver such as a gate or
other module
– Cannot be assigned in an initial or always block
Registers
• Registers represent storage elements
• Ex.
• reg reset;
• initial
• begin
• reset = 1’b1;
• #100 reset = 1’b0;
• end
Port connection rules
2-to-4 Line Decoder
2-to-4 Line Decoder
// 2-to-4 Line Decoder: Structural Verilog Desc.
not
gn0(not_S[0], S[0]),
gn1(not_S[1], S[1]);
and
g0(D[0], not_S[1], not_S[0]),
g1(D[1], not_S[1], S[0]),
g2(D[2], S[1], not_S[0]),
g3(D[3], S[1], S[0]);
g0(N[0], D[0], I[0]),
g1(N[1], D[1], I[1]),
g2(N[2], D[2], I[2]),
g3(N[3], D[3], I[3]);
endmodule
1 bit Full Adder
1-bit Full Adder
// define a 1-bit full adder
Module fulladd (sum, c_out, a, b, c_in);
// I/O port declarations
Output sum, c_out;
Input a, b, c_in;
//internal nets
Wire s1, c1, c2;
// instantiate logic gate primitives
Xor (s1, a, b);
And (c1, a, b);
Xor (sum, s1, c_in);
And (c2, s1, c_in);
Xor (c_out, c2, c1);
endmodule
4-bit Ripple Carry Adder
4-bit Full Adder
// define a 4-bit full adder
Module fulladd4 (sum, c_out, a, b, c_in);
// I/O port declarations
Output [3:0] sum;
Output c_out;
Input [3:0] a, b;
Input c_in;
// internal nets
Wire c1, c2, c3;
// instantiate four 1-bit full adders
Fulladd fa0(sum[0], c1, a[0], b[0], c_in);
Fulladd fa1(sum[1], c2, a[1], b[1], c1);
Fulladd fa2(sum[2], c3, a[2], b[2], c2);
Fulladd fa3(sum[3], c_out, a[3], b[3], c3);
endmodule