当前位置:网站首页>Verilog语法基础HDL Bits训练 08
Verilog语法基础HDL Bits训练 08
2022-07-30 11:17:00 【南邮学渣】
文章目录
Circuits:Combinational Logic:Arithmetic Circuits
一、Half adder

设计一个半加器
- RTL代码
module top_module(
input a, b,
output cout, sum );
assign {
cout,sum} = a + b;
endmodule
二、Full adder

设计一个全加器,相比较于半加器,全加器有一个进位输入
- RTL代码
module top_module(
input a, b, cin,
output cout, sum );
assign {
cout,sum} = a + b + cin;
endmodule
- 仿真波形图

三、3-bit binary adder

设计一个完整加法器
- RTL代码
module top_module(
input [2:0] a, b,
input cin,
output [2:0] cout,
output [2:0] sum );
integer i;
always @(*)begin
cout = 0;
sum = 0;
for(i=0;i<3;i=i+1)
if(i==0)
{
cout[0],sum[0]} = a[0] + b[0] +cin;
else
{
cout[i],sum[i]} = a[i] + b[i] + cout[i-1];
end
endmodule
- 仿真波形图

四、Adder

- RTL代码
module top_module (
input [3:0] x,
input [3:0] y,
output [4:0] sum);
wire [2:0]cout;
FA FA_inst1( .a(x[0]), .b(y[0]), .cin(1'b0), .cout(cout[0]), .sum(sum[0]) );
FA FA_inst2( .a(x[1]), .b(y[1]), .cin(cout[0]), .cout(cout[1]), .sum(sum[1]) );
FA FA_inst3( .a(x[2]), .b(y[2]), .cin(cout[1]), .cout(cout[2]), .sum(sum[2]) );
FA FA_inst4( .a(x[3]), .b(y[3]), .cin(cout[2]), .cout(sum[4]), .sum(sum[3]) );
endmodule
module FA(
input a, b, cin,
output cout, sum );
assign {
cout,sum} = a + b + cin;
endmodule
五、Signed addition overflow

设计一个有符号数的加法器,同时判断是否溢出
判断溢出的方法:两个加数最高位相同,且与和数最高位不同
- RTL代码
module top_module (
input [7:0] a,
input [7:0] b,
output [7:0] s,
output overflow
); //
assign s = a + b;
assign overflow = (a[7] & b[7] & ~s[7]) | (~a[7] & ~b[7] & s[7]);
endmodule
- 仿真波形图

六、100-bit binary adder

设计一个一百位的二进制加法器
- RTL代码
module top_module(
input [99:0] a, b,
input cin,
output cout,
output [99:0] sum );
assign {
cout,sum} = a + b + cin;
endmodule
七、4-digit BCD adder

使用已经编辑好的一位BCD码加法器实例化进行四位BCD码加法器设计
- RTL代码
module top_module (
input [15:0] a, b,
input cin,
output cout,
output [15:0] sum );
wire cout1,cout2,cout3;
bcd_fadd adder_inst1(.a(a[3:0]), .b(b[3:0]), .cin(cin), .cout(cout1), .sum(sum[3:0]) );
bcd_fadd adder_inst2(.a(a[7:4]), .b(b[7:4]), .cin(cout1), .cout(cout2), .sum(sum[7:4]) );
bcd_fadd adder_inst3(.a(a[11:8]), .b(b[11:8]), .cin(cout2), .cout(cout3), .sum(sum[11:8]) );
bcd_fadd adder_inst4(.a(a[15:12]), .b(b[15:12]), .cin(cout3), .cout(cout), .sum(sum[15:12]) );
endmodule
- 仿真波形图

边栏推荐
猜你喜欢

HJY-F931A/YJ three-phase voltage relay

NLP领域的最新研究进展

优酷VIP会员周卡只需7.5元,看《沉香如屑》用优酷视频

Is it too late to apply for PMP now to take the September exam?Share agile full-true mock questions

干货|语义网、Web3.0、Web3、元宇宙这些概念还傻傻分不清楚?(中)

FPGA刷题——计数器(简易秒表、可置位计数器、加减计数器)

Performance testing of API Gateway APISIX on Google Cloud T2A and T2D

stm32 RTC闹钟唤醒低功耗模式

Classes and Objects - 6 Default Member Functions

RY-D1/1 Voltage Relay
随机推荐
Microsoft SQL服务器被黑客入侵 带宽被窃取
Oracle中SQL语言和分页rownum分析
Vim plugin GrepIt
基于.NetCore开发博客项目 StarBlog - (16) 一些新功能 (监控/统计/配置/初始化)
208. 实现 Trie (前缀树)
feign远程调用时如何在请求头加入数据
我又造了个轮子:GrpcGateway
真正懂经营管理的CIO具备哪些特质
Still using Swagger?I recommend this interface management artifact with zero code intrusion
RY-D1/1 Voltage Relay
重写并自定义依赖的原生的Bean方法
实现web实时消息推送的7种方案
oracle export dmp file type as "crash dump file"
《跟唐老师学习云网络》 - 问题定位 - 主机通但容器不通
单片机开发之静态LED显示
STM32F1读取MLX90632非接触式红外温度传感器
oracle 导出dmp文件类型为“故障转储文件”
程序环境和预处理(详解)
TensorFlow custom training function
京东校招笔试题+知识点总结