You are provided with a BCD (binary-coded decimal) one-digit adder named bcd_fadd that adds two BCD digits and carry-in, and produces a sum and carry-out.
您将获得一个名为 bcd_fadd 的 BCD(二进制编码十进制)一位数加法器,该加法器将两个 BCD 数字相加并结转,并生成总和和结转。
module bcd_fadd ( input [3:0] a, input [3:0] b, input cin, output cout, output [3:0] sum );
实例化 4 个副本bcd_fadd以创建 4 位 BCD 纹波进位加法器。您的加法器应添加两个 4 位 BCD 数字(打包到 16 位向量中)和一个携带以产生 4 位总和并执行
module top_module (
input [15:0] a, b,
input cin,
output cout,
output [15:0] sum );
wire [2:0] cout_reg;
bcd_fadd fa1(
.a (a[3:0]),
.b (b[3:0]),
.cin (cin),
.cout (cout_reg[0]),
.sum (sum[3:0])
);
bcd_fadd fa2(
.a (a[7:4]),
.b (b[7:4]),
.cin (cout_reg[0]),
.cout (cout_reg[1]),
.sum (sum[7:4])
);
bcd_fadd fa3(
.a (a[11:8]),
.b (b[11:8]),
.cin (cout_reg[1]),
.cout (cout_reg[2]),
.sum (sum[11:8])
);
bcd_fadd fa4(
.a (a[15:12]),
.b (b[15:12]),
.cin (cout_reg[2]),
.cout (cout),
.sum (sum[15:12])
);
endmodule