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.

Initializing multidimensional array

Status
Not open for further replies.

verylsi

Full Member level 2
Joined
Mar 12, 2012
Messages
123
Helped
16
Reputation
32
Reaction score
16
Trophy points
1,308
Activity points
2,130
Hello All,

I am little confused with initializing multidimensional array..

If I need to initialize all values to '0' then in that case, I know that - (others=> (others=>'0') will work for me.

But I need to initialize 4 th element with "11111111" and rest all with "00000000" .


Then in this case, what should I do?

I tried -
signal tmp_ram: ram_type := ( (others=>'0'), (others=>'0'), (others=>'0'), (others=>'0'), (others=>'0'), (others=>'0'), (others=>'0'), (others=>'0'), (others=>'0'), (others=>'0'), (others=>'0'), (others=>'0'), ("11111111"), (others=>'0'), (others=>'0'), (others=>'0')) ;

but there must be a better way to do it.

Thanks
 
Last edited:

Hello All,

I am little confused with initializing multidimensional array..

If I need to initialize all values to '0' then in that case, I know that - (others=> (others=>'0') will work for me.

But I need to initialize 4 th element with "11111111" and rest all with "00000000" .


Then in this case, what should I do?

I tried -
signal tmp_ram: ram_type := ( (others=>'0'), (others=>'0'), (others=>'0'), (others=>'0'), (others=>'0'), (others=>'0'), (others=>'0'), (others=>'0'), (others=>'0'), (others=>'0'), (others=>'0'), (others=>'0'), ("11111111"), (others=>'0'), (others=>'0'), (others=>'0')) ;

but there must be a better way to do it.

Thanks

Here is one way:
signal tmp_ram: ram_type := (4 => (others => '1'), others => (others => '0')); -- I think this compiles correctly

Here is another way, you can decide if it is 'better' or just different. It's wordier than the previous method or other methods that will no doubt be proposed, but it is abundandly clear to the average reader how things are set...that has value as well.

function Init_Ram return ram_type is
variable RetVal: ram_type;
begin
RetVal := (others=> (others=>'0'));
RetVal(4) := (others => '1');
return(RetVal);
end function Init_Ram;
signal tmp_ram: ram_type := Init_Ram;

Kevin Jennings
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top