RegisterLogin  
Update Profile
   
You are here: Forum  
Minimize 
SVUG Community Forum
Subject: Assigning Packed Array to an Unpacked Array
Prev Next
You are not authorized to post a reply.

Author Messages
ArjunUser is Offline

Posts:3

06/17/2008 11:53 AM  
hey all,

 I want some help as to how a packed array can be assigned to an unpacked array. 

 
bit Ε:0] parity  // an 8 bit packed array

bit collect_parity[] ; // dynamic array .. hence unpacked


some where in a function , say I do

collect_parity= newΖ]    // assign the array size

and then want to assign

collect_parity = parity ; //  assigning packed to unpacked throws an error


This cannot be done . One obvious way out is to have "parity " also as an unpacked array. But is there a way to have this as packed and still be able to make this assignment ?

Also could you tell me , how the reverse assignment can be done too ... i.e unpacked to a packed.


Thanks



ArjunUser is Offline

Posts:3

06/17/2008 11:57 AM  


I am sorry ,

the line --> collect_parity= newΖ] // assign the array size

should have read --> collect_parity= newΖ] // assign the array size

ArjunUser is Offline

Posts:3

06/17/2008 11:58 AM  

the editor for some reason is not showing the size of the array I have set as 8 using the new [] operator
ShalomUser is Offline

Posts:11

06/18/2008 2:22 AM  
Try using the streaming operators.

Shalom
DaveUser is Offline

Posts:17

06/18/2008 9:15 AM  
Use a bitstream cast.  A bitstream cast works when source and destination types have a matching number of bits at the time of the assignment. If the destination of the assignment is dynamically sized, the cast will automatically pick the size to match the size of the source.

A good practice is to use typedefs for all your types.

typedef bit [ 31:0 ] packed_t;
typedef bit [ 7:0 ] unpacked_t[ ]

packed_t A;
unpacked_t B;

A = packed_t'(B); // creates an unpacked array of 4 bytes

B = unpacked_t'(A); // This works only when A has 4 bytes.


Dave Rich
You are not authorized to post a reply.
Forums > General Discussion > Main Discussion Area > Assigning Packed Array to an Unpacked Array



ActiveForums 3.7
  

 Copyright 2008 by SystemVerilog User Group Contact Us    Privacy Statement