「HDLBits题解」Arithmetic Circuits

本文分享了多个Verilog代码实例,包括基本的加法器模块如Hadd、Fadd,以及更复杂的加法器如Adder3、Exams中的加法模块。这些代码展示了从简单的二进制加法到多位数加法的设计过程,适合Verilog学习者参考和实践。
摘要由CSDN通过智能技术生成

本专栏的目的是分享可以通过HDLBits仿真的Verilog代码 以提供参考 各位可同时参考我的代码和官方题解代码 或许会有所收益

题目链接:Hadd - HDLBits

module top_module( 
    input a, b,
    output cout, sum );
	assign cout = a & b ; 
    assign sum = a ^ b ;
endmodule

题目链接:Fadd - HDLBits

module top_module( 
    input a, b, cin,
    output cout, sum );
	assign sum = a ^ b ^ cin ; 
    assign cout = (a & b) | (a & cin) | (b & cin) ; 
endmodule

题目链接: Adder3 - HDLBits

module top_module( 
    input [2:0] a, b,
    input cin,
    output [2:0] cout,
    output [2:0] sum );

    add1 u0(a[0], b[0], cin, sum[0], cout[0]) ;
    add1 u1(a[1], b[1], cout[0], sum[1], cout[1]) ;
    add1 u2(a[2], b[2], cout[1], sum[2], cout[2]) ;

endmodule


module add1 ( input a, input b, input cin, output sum, output cout );
 
// Full adder module here
    assign sum = a ^ b ^ cin ; 
    assign cout = (a & b) | (a & cin) | (b & cin) ; 
endmodule

题目链接:Exams/m2014 q4j - HDLBits

module top_module (
    input [3:0] x,
    input [3:0] y, 
    output [4:0] sum);

    wire [4:0] cout ; 

    add1 u0(x[0], y[0], 0, sum[0], cout[0]) ;
    add1 u1(x[1], y[1], cout[0], sum[1], cout[1]) ;
    add1 u2(x[2], y[2], cout[1], sum[2], cout[2]) ;
    add1 u3(x[3], y[3], cout[2], sum[3], cout[3]) ;

    assign sum[4] = cout[3] ;

endmodule


module add1 ( input a, input b, input cin, output sum, output cout );
 
// Full adder module here
    assign sum = a ^ b ^ cin ; 
    assign cout = (a & b) | (a & cin) | (b & cin) ; 
endmodule

题目链接:Exams/ece241 2014 q1c - HDLBits

module top_module (
    input [7:0] a,
    input [7:0] b,
    output [7:0] s,
    output overflow
); //
    // assign s = ...
    // assign overflow = ...
    assign s = a + b ;
    assign overflow = (~(a[7] ^ b[7])) & (s[7] != a[7]); 

endmodule

题目链接:Adder100 - HDLBits

module top_module( 
    input [99:0] a, b,
    input cin,
    output cout,
    output [99:0] sum );
	assign {cout, sum} = a + b + cin ;
endmodule

题目链接:Bcdadd4 - HDLBits

module top_module ( 
    input [15:0] a, b,
    input cin,
    output cout,
    output [15:0] sum 
); 
    wire [3:0] temp ; 

    bcd_fadd u0(a[3:0], b[3:0], cin, temp[0], sum[3:0]) ;
    bcd_fadd u1(a[7:4], b[7:4], temp[0], temp[1], sum[7:4]) ;
    bcd_fadd u2(a[11:8], b[11:8], temp[1], temp[2], sum[11:8]) ;
    bcd_fadd u3(a[15:12], b[15:12], temp[2], temp[3], sum[15:12]) ;

    assign cout = temp[3];

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

UCSD.KS

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

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

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

打赏作者

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

抵扣说明:

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

余额充值