当前位置:网站首页>Verilog grammar basics HDL Bits training 08
Verilog grammar basics HDL Bits training 08
2022-07-30 11:38:00 【nanyou scumbag】
文章目录
Circuits:Combinational Logic:Arithmetic Circuits
一、Half adder
Design one and a half adder
- RTL代码
module top_module(
input a, b,
output cout, sum );
assign {
cout,sum} = a + b;
endmodule
二、Full adder
Design a full adder,Compared with a half adder,Full adder has a carry input
- RTL代码
module top_module(
input a, b, cin,
output cout, sum );
assign {
cout,sum} = a + b + cin;
endmodule
- 仿真波形图
三、3-bit binary adder
Design a full 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
The number of design a symbol adder,同时判断是否溢出
判断溢出的方法:The same two addend that high,And unlike and highest
- 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
Design a one hundred - 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
Use edit good aBCDAdder instantiation of fourBCDCode adder is designed
- 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
- 仿真波形图
边栏推荐
- 单片机开发之静态LED显示
- Current relay JL-8GB/11/AC220V
- 电流继电器JL-8GB/11/AC220V
- ADC0808/9 signal acquisition developed by single chip microcomputer
- Log4j additivity属性简介说明
- 《跟唐老师学习云网络》 - 问题定位 - 主机通但容器不通
- 【云筑共创】华为云携手鸿蒙,端云协同,培养创新型开发者
- PanGu-Coder: 函数级的代码生成模型
- The use and principle of distributed current limiting reduction RRateLimiter
- How to add data to the request header when feign is called remotely
猜你喜欢
干货|语义网、Web3.0、Web3、元宇宙这些概念还傻傻分不清楚?(中)
编译Hudi
时间序列曲线相似性
High energy output!Tencent's internal MyCat middleware manual, both theoretical and practical
Interviewer: Redis bloom filter and the cuckoo in the filter, how much do you know?
AB test summary
API 网关 APISIX 在Google Cloud T2A 和 T2D 的性能测试
STM32F1读取MLX90632非接触式红外温度传感器
RY-D1/1 Voltage Relay
高能产出!腾讯内部的MyCat中间件手册,理论实操齐下
随机推荐
面试官:Redis中的布隆过滤器与布谷鸟过滤器,你了解多少?
MySQL之数据库维护
高能产出!腾讯内部的MyCat中间件手册,理论实操齐下
重写并自定义依赖的原生的Bean方法
LeetCode_235_二叉搜索树的最近公共祖先
【ASP.NET Core】选项类的依赖注入
分布式限流 redission RRateLimiter 的使用及原理
三个点语法和DOM观察者
自定义查询--关于倒排索引的研究
域名怎么注册备案解析?
Current relay JL-8GB/11/AC220V
RY-D1/1 Voltage Relay
Transfer Learning Technology Training
数据库事务,JDBC操作和数据类型
decodeURIComponent(), eval(), encodeURIComponent()
Voltage relay h2d SRMUVS - 100 vac - 2
牛客-TOP101-BM42
基于MySQL数据库,Redis缓存,MQ消息中间件,ES搜索引擎的高可用方案解析
零代码开发入门:快速上手DIY函数公式的5个步骤
文本的对齐方式、行高、空间 等总结