这道题有两种解法
1、
module top_module(
input [7:0] in,
output [7:0] out
);
assign out = {in[0],in[1],in[2],in[3],in[4],in[5],in[6],in[7]};
endmodule
2、
module top_module(
input [7:0] in,
output [7:0] out
);
always@*
begin
integer i;
for(i = 0;i <8;i = i+1)
out[i] = in[7-i];
end
endmodule
错误解答
module top_module(
input [7:0] in,
output [7:0] out
);
integer i;
for(i = 0;i <8;i = i+1)
out[i] = in[7-i];
endmodule
错因:for语句不能单独使用,需放在语句块如always 、initial 等等中使用。