16-bit adder

This commit is contained in:
2024-06-13 21:13:15 -07:00
parent bebe8fa2d0
commit a7f7723702
3 changed files with 50 additions and 0 deletions

View File

@@ -1,6 +1,15 @@
clean:
-rm *.vcd *.vvp
add16_tb: add16_tb.vcd
gtkwave add16_tb.vcd &
add16_tb.vcd: add16_tb.vvp
vvp add16_tb.vvp
add16_tb.vvp: add16.v add16_tb.v
iverilog -o add16_tb.vvp add16_tb.v
fulladder_tb: fulladder_tb.vcd
gtkwave fulladder_tb.vcd &

22
add16.v Normal file
View File

@@ -0,0 +1,22 @@
`ifndef _add16_v
`define _add16_v
`include "halfadder.v"
`include "fulladder.v"
module Add16 (input [15:0] a, input [15:0] b, output [15:0] out);
wire [16:1] c;
genvar i;
generate
for (i=0; i<16; i=i+1)
begin
if (i==0)
HalfAdder u1 (.a(a[i]), .b(b[i]), .sum(out[i]), .carry(c[i+1]));
else
FullAdder u1 (.a(a[i]), .b(b[i]), .c(c[i]), .sum(out[i]), .carry(c[i+1]));
end
endgenerate
endmodule
`endif

19
add16_tb.v Normal file
View File

@@ -0,0 +1,19 @@
`include "add16.v"
module Add16_test;
reg [15:0] a, b;
wire [15:0] out;
integer i;
initial begin
$dumpfile("add16_tb.vcd");
$dumpvars;
a=123;
b=456;
#1;
$finish();
end
Add16 u1(.a(a), .b(b), .out(out));
endmodule