Verilog HDL 程序
1 编写求补码的 Verilog HDL 程序,输入是带符号的 8 位二进制数。
2 有一个比较电路,当输入的一位 8421BCD 码大于 4 时,输出为 1,否则为
0。试编写出 Verilog HDL 程序。
1
module sig2component(clk, rst_n, din, dout)
input clk;
input rst_n;
input [7:0] din;
output [7:0] dout;
always @ (posedge clk or negedge rst_n)
if (!rst_n)
dout <= 0;
else if (din[7]) begin
dout[6:0] <= ~din[6:0] + 7'd1;
dout[7] <= din[7];
end
else
dout <= din;
endmodule
2
module compare(clk, rst_n, din, flag_out)
input clk, rst_n;
input [3:0] din;
output flag_out;
always @ (posedge clk or negedge rst_n)
if (!rst_n)
flag_out <= 0;
else if (din > 4'd4)
flag_out <= 1'b1;
else
flag_out <= 1'b0;
评论2