1 Star 0 Fork 0

打野/Verilog练习代码

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
practice2.v 1.52 KB
一键复制 编辑 原始数据 按行查看 历史
打野 提交于 2023-10-12 21:24 +08:00 . 2023-10-12
//2023-10-12 姜青羊
//补码转换练习
/*`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;
assign y[7] = a[7];
assign a_comp = a[7]?y:a;
endmodule
*/
/*
//把b变量去掉
`timescale 1ns/10ps
module comp_conv (
a,
a_comp
);
input[7:0] a;
output[7:0] a_comp;
wire[7:0] y;
assign y[6:0] = ~a[6:0]+1;
assign y[7] = a[7];
assign a_comp = a[7]?y:a;
endmodule
*/
//把38、39合成一句来写,用拼接的方式
`timescale 1ns/10ps
module comp_conv (
a,
a_comp
);
input[7:0] a;
output[7:0] a_comp;
wire[7:0] y;
//assign y[6:0] = ~a[6:0]+1;
//assign y[7] = a[7];
assign y = {a[7],~a[6:0]+1};
assign a_comp = a[7]?y:a; //这里还能简洁,连y都不用 a_comp = a[7]?{a[7],~a[6:0]+1}: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;
#3000 $stop;
end
always #10 a_in = a_in+1;
comp_conv u_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

搜索帮助