输入多位的数据,输出逆序的数据,如输入 11001010,则要求输出01010011
这里要采用for语句
module top_module(
input [99:0] in,
output [99:0] out
);
integer i = 0;
always @(*)
for(i = 0; i<100; i= i+1)
out[i] = in[99-i];
endmodule
下面是系统推荐的写法,加入了$bits()函数,这个函数的功能就是获取到数据的位数
module top_module (
input [99:0] in,
output reg [99:0] out
);
always @(*) begin
for (int i=0;i<$bits(out);i++)
// $bits() is a system function that returns the width of a signal.
out[i] = in[$bits(out)-i-1];
// $bits(out) is 100 because out is 100 bits wide.
end
endmodule