cancel
Showing results for
Did you mean:
Highlighted
Contributor
482 Views
Registered: ‎07-26-2018

## Error "array index out of the range"

When i try to do "open elaborated design"  it gives me this error. (error in the multiplication section.)

Thank you.

```    subtype mask5 is integer range -16 to 15;
type mask_type is array(integer range <>) of mask5;
constant mask : mask_9 := (-1, -1, -1, -1, 8, -1, -1, -1, -1);

--

signal p1,p2,p3,p4,p5,p6,p7,p8,p9 : std_logic_vector(8 downto 0);
p1<='0' & window(71 downto 64);
p2<='0' & window(63 downto 56);
p3<='0' & window(55 downto 48);
p4<='0' & window(47 downto 40);
p5<='0' & window(39 downto 32);
p6<='0' & window(31 downto 24);
p7<='0' & window(23 downto 16);
p8<='0' & window(15 downto 8);
p9<='0' & window(7 downto 0);

---

variable sum : integer:= 0;
sum := 0;
sum := (  to_integer( unsigned(p1)) * mask(1)+
to_integer( unsigned(p2)) * mask(2)+
to_integer( unsigned(p3)) * mask(3)+
to_integer( unsigned(p4)) * mask(4)+
to_integer( unsigned(p5)) * mask(5)+
to_integer( unsigned(p6)) * mask(6)+
to_integer( unsigned(p7)) * mask(7)+
to_integer( unsigned(p8)) * mask(8)+
to_integer( unsigned(p9)) * mask(9));         ```

1 Solution

Accepted Solutions
Highlighted
Explorer
461 Views
Registered: ‎06-25-2014

You need to reference mask() starting from index 0 to fix this error:

sum := (  to_integer( unsigned(p1)) * mask(0)+
to_integer( unsigned(p2)) * mask(1)+
to_integer( unsigned(p3)) * mask(2)+
to_integer( unsigned(p4)) * mask(3)+
to_integer( unsigned(p5)) * mask(4)+
to_integer( unsigned(p6)) * mask(5)+
to_integer( unsigned(p7)) * mask(6)+
to_integer( unsigned(p8)) * mask(7)+
to_integer( unsigned(p9)) * mask(8));

Highlighted
Explorer
462 Views
Registered: ‎06-25-2014

You need to reference mask() starting from index 0 to fix this error:

sum := (  to_integer( unsigned(p1)) * mask(0)+
to_integer( unsigned(p2)) * mask(1)+
to_integer( unsigned(p3)) * mask(2)+
to_integer( unsigned(p4)) * mask(3)+
to_integer( unsigned(p5)) * mask(4)+
to_integer( unsigned(p6)) * mask(5)+
to_integer( unsigned(p7)) * mask(6)+
to_integer( unsigned(p8)) * mask(7)+
to_integer( unsigned(p9)) * mask(8));