Verilog - Combinational Circuit
Verilog - Combinational Circuit
4b10_11
Underscores are ignored Base format (d,b,o,h) Decimal number representing size in bits
8b0000_0000 8b0xx0_1xx1
Hexadecimal literals
32h0a34_def1 16haxxx 16 haxxx
Decimal literals
32d42
Well learn how to actually assign literals to nets a little later
Verilog Basics
History of hardware design languages y g g g Data types Structural Verilog Functional Verilog
Gate level Register transfer level High-level behavioral
FA FA FA FA
module adder( input [3:0] A B A, B, output cout, output [3:0] S ); wire c0, c1, c2; FA fa0( A[0], B[0], FA fa1( A[1], B[1], FA fa2( A[2], B[2], FA fa3( A[3], B[3], endmodule 1b0, c0, c1, c2, c0, c1, c2, cout, S[0] S[1] S[2] S[3] ); ); ); );
B
4
adder
4
module adder( A, B, cout, sum ); input [3:0] A; input [3:0] B; output p cout; ; output [3:0] sum; // HDL modeling of // adder f dd functionality ti lit endmodule
cout
sum
B
4
adder
4
cout
sum
FA
c
adder
cout S
FA
FA
FA
FA
module adder( input [3:0] A, B, output cout, output [3:0] S ); wire c0, c1, c2; FA fa0( ... ); FA fa1( ... ); FA fa2( ... ); FA fa3( ... ); endmodule
adder
cout S
FA
FA
FA
FA
module adder( input [3:0] A, B, output cout, output [3:0] S ); wire c0, c1, c2; FA fa0( A[0] B[0] A[0], B[0], FA fa1( A[1], B[1], FA fa2( A[2], B[2], FA fa3( A[3], B[3], endmodule 1b0 1b0, c0, c1, c2, c0 c0, c1, c2, cout, S[0] S[1] S[2] S[3] ); ); ); );
Carry Chain
For all but the smallest modules, connecting ports by name yields clearer and less buggy code code.
Lets review how to turn our schematic diagram into structural Verilog di i t t t l V il
FA
FA
FA
FA
Lets review how to turn our schematic diagram into structural Verilog di i t t t l V il
FA
FA
FA
FA
input module adder( ... ); [3:0] A, B, output cout, output [3:0] S ); wire c0, c1, c2; FA f 0( A[0]) B[0] fa0( ... );B[0], A[0], FA fa1( ... );B[1], A[1], FA fa2( ... );B[2], A[2], FA fa3( ... );B[3], A[3], endmodule 1b0 1b0, c0, c1, c2, c0, 0 c1, c2, cout, S[0] S[1] S[2] S[3] ) ); ); ); );
Verilog Fundamentals
History of hardware design languages y g g g Data types Structural Verilog Functional Verilog
Gate level Register transfer level High-level behavioral
FA FA FA FA
module adder( input [3:0] A B A, B, output cout, output [3:0] S ); wire c0, c1, c2; FA fa0( A[0], B[0], FA fa1( A[1], B[1], FA fa2( A[2], B[2], FA fa3( A[3], B[3], endmodule 1b0, c0, c1, c2, c0, c1, c2, cout, S[0] S[1] S[2] S[3] ); ); ); );
wire x0, x1; nor nor0( x0, n0, n1 ); nor nor1( x1, n2, n3 ); wire y0, y1; or or0( y0, x0, sel[0] ); or or1( y1, x1, sel_b[0] ); nand nand0( out, y0, y1 ); out y0 endmodule out