四位全加器的设计与仿真

若对你有用,记得点赞、关注我哦!

博客总领目录请看这篇,不看后悔

软件工程专业大学四年学什么_大学近代史学分是多少-CSDN博客icon-default.png?t=N7T8https://blog.csdn.net/qq_41587612/article/details/104362661B站同名up猪,欢迎关注我的账号鸽子不二的个人空间-鸽子不二个人主页-哔哩哔哩视频哔哩哔哩鸽子不二的个人空间,提供鸽子不二分享的视频、音频、文章、动态、收藏等内容,关注鸽子不二账号,第一时间了解UP主动态。icon-default.png?t=N7T8https://space.bilibili.com/204913846

计算机组成原理期末复习【超实用】

一位全加器的设计与仿真

简单运算器的设计与仿真

八位比较器的设计与仿真

1/2分频器的设计和仿真

四选一多路选择器的设计与仿真

1. 实验题目

     四位全加器的设计与仿真

2. 实验目的

     利用实验一实现的模块设计一个四位全加器并仿真测试。

3. 实验要求

     设计模块名称fulladd_4bit,输入端口 a,b,c_in。输出端口sum,c_out。测试要充分。

4. 程序代码

VerilogHDL代码:
module full_adder4(sum,cout,a,b,cin);
input [3:0] a,b;
input cin;
output cout;
output [3:0] sum;
assign {count,sum} = a+b+cin;
endmodule

Test bench仿真代码:
`timescale 1ns/1ns 
`include "full_adder4.v"
module fulladd_4bit;   //测试模块的名字
reg[3:0] a,b;   //测试输入信号定义为reg型
reg cin;  
wire[3:0] sum;  //测试输出信号定义为wire型
wire cout; integer i,j;
full_adder4 adder(sum,cout,a,b,cin);   //调用测试对象
always #5 cin=~cin;  //设定cin的取值
initial 
begin  a=0;b=0;cin=0; 
for(i=1;i<16;i=i+1)
#10   a=i;   //设定a的取值
end 
initial
begin 
for(j=1;j<16;j=j+1)
#10   b=j;  //设定b的取值
end
initial
//定义结果显示格式
begin 
$monitor($time,,,"%d + %d + %b={%b,%d}",a,b,cin,cout,sum);
#160 
$finish; 
end 
endmodule

5. 实验结果

       根据代码#5设定每隔5个时间单位cin从0变换到1或从1变换到0,整形i、j的范围是[1,16)则a与b的取值范围为[0,15],即a、b转化为二进制数0000到1111,当a=b=1000,cin=0时sum需要进位,此时的cout由0变为1,余下的变化规则同实验一。

  • 23
    点赞
  • 140
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
以下是基于 Verilog 的四位全加器的代码实现及仿真设计。 ``` module full_adder( input a, input b, input cin, output sum, output cout ); assign sum = a ^ b ^ cin; assign cout = (a & b) | (a & cin) | (b & cin); endmodule module four_bit_adder( input [3:0] a, input [3:0] b, input cin, output [3:0] sum, output cout ); wire c1, c2, c3; full_adder fa0(a[0], b[0], cin, sum[0], c1); full_adder fa1(a[1], b[1], c1, sum[1], c2); full_adder fa2(a[2], b[2], c2, sum[2], c3); full_adder fa3(a[3], b[3], c3, sum[3], cout); endmodule module four_bit_adder_tb; reg [3:0] a; reg [3:0] b; reg cin; wire [3:0] sum; wire cout; four_bit_adder test(a, b, cin, sum, cout); initial begin $dumpfile("four_bit_adder_tb.vcd"); $dumpvars(0, four_bit_adder_tb); // Test case 1: 2 + 3 = 5 a = 2; b = 3; cin = 0; #10; $display("Test case 1: %d + %d = %d", a, b, sum); $display("Carry out: %d", cout); // Test case 2: 10 + 5 = 15 a = 10; b = 5; cin = 0; #10; $display("Test case 2: %d + %d = %d", a, b, sum); $display("Carry out: %d", cout); // Test case 3: 8 + 8 = 0, carry out 1 a = 8; b = 8; cin = 0; #10; $display("Test case 3: %d + %d = %d", a, b, sum); $display("Carry out: %d", cout); // Test case 4: 7 + 9 = 0, carry out 1 a = 7; b = 9; cin = 0; #10; $display("Test case 4: %d + %d = %d", a, b, sum); $display("Carry out: %d", cout); // Test case 5: 15 + 1 = 0, carry out 1 a = 15; b = 1; cin = 0; #10; $display("Test case 5: %d + %d = %d", a, b, sum); $display("Carry out: %d", cout); $finish; end endmodule ``` 以上代码中,`full_adder` 模块实现了单个全加器的功能,`four_bit_adder` 模块则通过四个全加器的级联实现了四位全加器的功能。测试模块 `four_bit_adder_tb` 中包含了五个测试用例,用于验证四位全加器的正确性。 在仿真中,可以使用 Verilog 模拟器,例如 ModelSim 或 Vivado 进行仿真。在仿真中,将 `four_bit_adder_tb` 作为顶层模块进行仿真即可。仿真结果将被输出到 `four_bit_adder_tb.vcd` 文件中。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值