Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Bit swapping in Verilog

Status
Not open for further replies.

andre_luis

Super Moderator
Staff member
Joined
Nov 7, 2006
Messages
9,591
Helped
1,190
Reputation
2,399
Reaction score
1,206
Trophy points
1,403
Location
Brazil
Activity points
55,665
A time ago I came across a piece of code intended to perform a bit reversing operation ( swapping the most significant bits toward less significant bits, and vice-versa ), but it seemed that would not work, like if one would superimpose the value of the other. Is it correct ?

Code:
for(i=0;i<8;i=i+1)
   begin 
      a_temp<=a[7-i];
      a[7-i]<=a[i];
      a[i]<=a_temp;      
   end
end
 

Re: reverse bits in verilog

The original code works. By using nonblocking assignments, the left-hand side of expressions is updated after the end of the initial block.
 

Re: reverse bits in verilog

Thanks for correcting me, so can we assume that the code below will perform the same bit swapping task, but coded in a simplest manner ?

Code:
a[0:7] <= a[7:0] ;
 

Re: reverse bits in verilog

Thanks for correcting me, so can we assume that the code below will perform the same bit swapping task, but coded in a simplest manner ?

Code:
a[0:7] <= a[7:0] ;
No, that will not work. You cannot have a select of bits in the reverse order.

In SystemVerilog, there is a streaming operator that will reverse the bits for you.
Code:
a <= {<<{ a }};

See section 11.4.14 Streaming operators (pack/unpack) in the IEEE 1800-2012 LRM.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top