定义一个4位输入,8位输出,然后对每个输入都判断是否为1如果为一,就把输出寄存器,相应的位变为01,否则就变为11本人感觉没什么问题,但是就是仿真不对,求教,求指点。
module cs(clk,rest_n,in,cnt,out); input clk,rest_n; input [3:0] in; output [1:0] cnt; output [7:0] out; reg [1:0] cnt; reg [7:0] dout; always@(posedge clk,negedge rest_n)begin if(!rest_n)begin dout <= 8'h00; cnt <= 2'b00; end else begin if(in[cnt]) begin {dout[(cnt << 1) + 1],dout[cnt << 1]} <= 2'b01; end else begin {dout[(cnt << 1) + 1],dout[cnt << 1]} <= 2'b11; end cnt <= cnt + 1'b1; end end assign out = dout; endmodule
请了解的网友,帮忙在右下角留言。