Professional Documents
Culture Documents
L3: Introduction To Verilog (Combinational Logic)
L3: Introduction To Verilog (Combinational Logic)
Verilog
(Combinational Logic)
Logic)
Verilog References:
• Samir Palnitkar, Verilog HDL, Pearson Education (2nd edition).
• Donald Thomas, Philip Moorby, The Verilog Hardware Description Language, Fifth
Edition, Kluwer Academic Publishers.
• J. Bhasker, Verilog HDL Synthesis (A Practical Primer), Star Galaxy Publishing
Verilog
input a,b;
output sum;
assign sum <= {1b’0, a} + {1b’0, b};
32
32
+ SUM DQ
32
sel
counter
interconnect
a
b F(a,b,c,d)
c LUT G(a,b,c,d)
d
ADR
R/W
RAM DATA
input a, b, sel;
Specify each port as input, output,
outbar, sel); a
1
input a, b, sel;
out
output out, outbar;
b 0 outbar
assign out = sel ? a : b;
sel
endmodule
Arithmetic: +, -, *
Select area and set inputs through overwrite or insert menu (under edit)
Glitch
L3: 6.111 Spring 2004 Introductory Digital Systems Laboratory 7
Gate Level Description
Description
outbar, sel);
input a, b, sel;
a
output out, outbar;
out1
wire out1, out2, selb;
sel
and a1 (out1, a, sel);
out
not i1 (selb, sel);
outbar
and a2 (out2, b , selb);
selb
out2
or o1 (out, out1, out2);
b
assign outbar = ~out;
endmodule
if (sel) out = a;
Statements within the always
else out = b;
end
Surround multiple statements in a
single always block with begin/end.
endmodule
outbar, sel);
outbar, sel);
input a, b, sel;
input a, b, sel;
reg out;
reg out;
begin begin
if (sel) out = a; case (sel)
else out = b; 1’b1: out = a;
end 1’b0: out = b;
endcase
assign outbar = ~out; end
endmodule
(4’b1010 if a 4-bit binary value, 16’h6cda is a 16 bit hex number, and 8’d40 is an 8-bit decimal value)
outbar, sel);
input[7:0] a, b;
8
input sel;
reg[7:0] out;
out
always @ (a or b or sel) b 0 outbar
begin 8 8
if (sel) out = a;
else out = b;
sel
end
endmodule
input[31:0] a,b;
output[31:0] sum;
assign sum = a + b;
endmodule
input[31:0] a,b;
input cin;
output[31:0] sum;
output cout;
endmodule
a 00 input a,b,c;
output out;
c 10
always @(a or b or c or sel)
2
begin
case (sel)
2'b01: out = b;
2'b10: out = c;
3-to-1 MUX
endcase
endmodule
input a,b,c;
output out;
a 00
reg out;
b 01 D Q out
always @(a or b or c or sel)
begin c
10
case (sel)
G
2'b00: out = a;
2
2'b01: out = b;
2'b10: out = c;
sel
endcase
end
sel[1]
endmodule
sel[0]
begin
case (sel)
endcase
end
endmodule
case (sel)
branches of conditionals and
2'b00: out = a;
2'b01: out = b;
assign all signals from all
2'b10: out = c; branches
input [3:0] i;
0 I3 output [1:0] e;
1 I2 E1 reg e;
1
0 I1 E0 0 always @(i)
0 I0 begin
if (i[0]) e = 2’b00;
0001 00
else e = 2’bxx;
0010 01 end
0100 10 endmodule
1000 11
all others XX
What is the resulting circuit?
input [3:0] i;
output [1:0] e;
I3
reg e;
E0
always @(i)
begin
I1
E1
if (i == 4’b0001) e = 2’b00;
I0
else if (i == 4’b0010) e = 2’b01;
else e = 2’bxx;
end
endmodule
A[31:0] B[31:0]
F2 F1 F0 Function
0 0 0
A+B
32’d1 32’d1
F[0] 0 0 1
A+1
0 1 0 1
0 1 0
A-B
F[2:0]
0 1 1
A-1
+ - *
1 0 X
A*B
00 01 10
F[2:1]
R[31:0]
module mux32two(i0,i1,sel,out);
input [31:0] i0,i1,i2;
begin
endcase
end
endmodule
module mux32two(i0,i1,sel,out);
module mux32three(i0,i1,i2,sel,out);
32’d1 32’d1
module add32(i0,i1,sum);
F[0]
0 1 0 1
module sub32(i0,i1,diff);
module mul16(i0,i1,prod);
F[2:0]
+ - *
Declaration of the ALU Module:
module alu(a, b, f, r);
00 01 10
F[2:1]
input [31:0] a, b;
input [2:0] f;
corresponding
submodule’s wire/reg in
port name outer module