Ai
1 Star 0 Fork 0

打野/Verilog练习代码

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
comp_conv(1).v 1.11 KB
一键复制 编辑 原始数据 按行查看 历史
打野 提交于 2023-08-27 20:23 +08:00 . 2023-8-27
//2023-8-26,(姜青羊)
//complement conversion(补码转换逻辑)
`timescale 1ns/10ps
module comp_conv (
a,
a_comp
);
input[7:0] a;
output[7:0] a_comp;
wire[6:0] b; //按位取反的幅度位;
wire[7:0] y; //负数的补码;
assign b=~a[6:0];
assign y[6:0]=b+1; //按位取反+1;
assign y[7]=a[7]; //符号位不变;
assign a_comp=a[7]?y:a; //问号冒号语句来二选一;
endmodule
//-----testbench of comp_conv-----
module tb_comp_conv ();
reg[7:0] a_in;
wire[7:0] y_out;
initial begin
a_in<=0; //标准的测试方法是把所有的都测(遍历)到,即从全0走到全1,8位会有256种
#3000 $stop; //用initial这种赋值很慢,用always # 的方法来写很快
//每个值坚持10ns,那就是2560ns,那么3000ns足够了
end
always #10 a_in=a_in+1;
comp_conv c_comp_conv (
.a(a_in),
.a_comp(y_out)
);
endmodule
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/fight_wild/verilog-code.git
git@gitee.com:fight_wild/verilog-code.git
fight_wild
verilog-code
Verilog练习代码
master

搜索帮助