4-digit BCD adder
题目如下:
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.
代码如下:
module top_module (
input [15:0] a, b,
input cin,
output cout,
output [15:0] sum );
wire [2:0] cout_temp;
bcd_fadd bcd_1(a[3:0],b[3:0],cin,cout_temp[0],sum[3:0]);
bcd_fadd bcd_2(a[7:4],b[7:4],cout_temp[0],cout_temp[1],sum[7:4]);
bcd_fadd bcd_3(a[11:8],b[11:8],cout_temp[1],cout_temp[2],sum[11:8]);
bcd_fadd bcd_4(a[15:12],b[15:12],cout_temp[2],cout,sum[15:12]);
endmodule

浙公网安备 33010602011771号