Bcdadd4

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

eachanm

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值