代码拉取完成,页面将自动刷新
//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
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。