module a(
input [3:0] a,
input clk,
input rst_n,
output reg [7:0] out
);
always@(posedge clk or negedge rst_n)
begin
if(~rst_n)
out<=8'b0000_0000;
else
case(a)
3'b000:out[0]=1'b1;
3'b001:out[1]=1'b1;
3'b010:out[2]=1'b1;
3'b011:out[3]=1'b1;
3'b100:out[4]=1'b1;
3'b101:out[5]=1'b1;
3'b110:out[6]=1'b1;
3'b111:out[7]=1'b1;
endcase
end
endmodule
module a(
input [3:0] a,
input clk,
input rst_n,
output reg [7:0] out
);
always@(posedge clk or negedge rst_n)
begin
if(~rst_n)
out<=8'b0000_0000;
else
case(a)
3'b000:out[0]=1'b1;
3'b001:out[1]=1'b1;
3'b010:out[2]=1'b1;
3'b011:out[3]=1'b1;
3'b100:out[4]=1'b1;
3'b101:out[5]=1'b1;
3'b110:out[6]=1'b1;
3'b111:out[7]=1'b1;
endcase
end
endmodule
2
举报
-
卿小小_9e6:
如果是独热码(one-hot)的情况,不建议这种写法。
你的写法容易导致out[0]~out[7]在其他状态出现状态锁存的情况。
-