「HDLBits题解」Arithmetic Circuits

本专栏的目的是分享可以通过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
相关推荐
芒果树技术26 分钟前
MT-PXle RIO模块【高性能FPGA+ LVDS】采用FPGA实现高效LVDS通讯
fpga开发·模块测试·fpga
明月清了个风2 小时前
STM32初始化串口重定向后printf调试信息不输出的问题
stm32·单片机·fpga开发·嵌入式软件
通信小呆呆6 小时前
电路思维下的 Verilog:如何区分组合逻辑与时序逻辑
fpga开发·电路·时序逻辑·跨时钟域·组合逻辑
嵌入式-老费6 小时前
Zynq开发实践(FPGA之uart接收)
fpga开发
ShiMetaPi1 天前
操作【GM3568JHF】FPGA+ARM异构开发板 使用指南:蓝牙
arm开发·嵌入式硬件·fpga开发·rk3568
知识充实人生1 天前
静态时序分析详解之时序路径类型
fpga开发·时序路径·关键路径
9527华安2 天前
Xilinx系列FPGA实现DP1.4视频收发,支持4K60帧分辨率,提供2套工程源码和技术支持
fpga开发·音视频·dp1.4·4k60帧
cycf2 天前
高速接口基础
fpga开发
forgeda2 天前
从Vivado集成Lint功能,看FPGA设计的日益ASIC化趋势
fpga开发·vivado·lint·eco·静态检查功能
hexiaoyan8273 天前
国产化FPGA开发板:2050-基于JFMK50T4(XC7A50T)的核心板
fpga开发·工业图像输出·vc709e板卡·zynq 通用计算平台·模拟型号处理