bit mirroring in verilog...

Status
Not open for further replies.

davorin

Advanced Member level 3
Joined
Jun 7, 2003
Messages
901
Helped
11
Reputation
22
Reaction score
4
Trophy points
1,298
Location
Switzerland
Activity points
7,349
Is there an easy way of mirroring a bus signal in Verilog instead of using:

Code:
assign data_out = {data[0],data[1],data[2],data[3],.......};
 

In Verilog 2001 you can do this, but it's still not pretty:
Code:
module bitreverse (data, data_out);
  parameter bits = 16;
  input  [bits-1:0] data;
  output [bits-1:0] data_out;
  genvar g;

  generate for (g=0; g<bits; g=g+1) begin:bit
    assign data_out[g] = data[bits-1-g];
  end endgenerate
endmodule
 

reg[width-1:0] data_out;
always@(data) begin:reverse_bit
integer i;
for(i=0; i<width;i=i+1)
data_out = data[width-1-i];
end
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…