bluespec.com Forum Index bluespec.com
Bluespec Forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

register

 
Post new topic   Reply to topic    bluespec.com Forum Index -> Designing with BSV's Rules, Interfaces, ...
View previous topic :: View next topic  
Author Message
flashdisk



Joined: 29 May 2012
Posts: 56

PostPosted: Thu Aug 09, 2012 5:16 am    Post subject: register Reply with quote

hey,

I have a register which I use in saving the multiplication of 2 binary numbers how can I return specific number of bits of the register for example
if I have a register with size of 10 how can I return the last 5 bits from it

reg A=1010100000
the return value should be
A=10101
Back to top
View user's profile Send private message
quark
Site Admin


Joined: 02 Nov 2007
Posts: 500

PostPosted: Thu Aug 09, 2012 12:32 pm    Post subject: Re: register Reply with quote

If the size of the register is known, you can just do this:
Code:
Reg#(Bit#(10)) rgA <- mkRegU;
Bit#(5) ex1 = rgA[9:5];

You can also use the library function "truncateLSB", which truncates from the LSB side:
Code:
Bit#(5) ex2 = truncateLSB(rgA);

The number of bits is not a parameter to "truncateLSB"; instead it is determined from the context. Since 5 bits are expected in the above example, it will return a 5-bit value. (This is in contrast with the function "truncate", which truncates from the MSB side, returning the lower bits.)

If the size of the register is parameterized, you can still extract 5 bits by doing arithemetic on the types:
Code:
function Bit#(5) getTopFiveBits(Bit#(n) v);
   Integer hi = fromInteger(n)-1;
   Integer lo = fromInteger(n)-5;
   return v[hi:lo];
endfunction

Does that answer your question?
Back to top
View user's profile Send private message
flashdisk



Joined: 29 May 2012
Posts: 56

PostPosted: Sat Aug 11, 2012 7:20 am    Post subject: Reply with quote

I think it will be helpful thank you so much but what does MKregU make?
can I do this reg A <-MKregU(0);

thanks
Back to top
View user's profile Send private message
quark
Site Admin


Joined: 02 Nov 2007
Posts: 500

PostPosted: Sat Aug 11, 2012 8:42 pm    Post subject: Reply with quote

The module "mkRegU" is a register without a reset value; the U stands for uninitialized. In the above examples, you can use "mkReg(0)" if you want to instantiate a register which is synchronously reset to 0.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    bluespec.com Forum Index -> Designing with BSV's Rules, Interfaces, ... All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
bluespec.com topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP