Das Ganze dient erst einmal zur Übung, bzw. zum Verständnis mit dem
Umgang von arithmetischen Operationen.
Nun möchte ich Werte einlesen, welche indiziert werden, um später eine
Positionsbestimmung zu realisieren. Ich habe mir dabei jetzt folgendes
gedacht: Ich definiere ein Array aus std_logic_vectoren:
1 | type table is Array (6 downto 0) of std_logic_vector (7 downto 0);
|
und definiere nun Werte
1 | constant vec_value: table := ("00000000","00000001","00000010","00000010","00000010","00000110","00010010");
|
Um nun die Summe aller enthaltenen Vektorewerte zu bestimmen, würde ich
eine For-Schleife definieren, welche so oft iteriert, so viele Elemente
auch vorhanden sind.
1 | signal array_length : std_logic_vector(vec_value'length downto 0);
|
2 | signal tmp : integer := 0 ;
|
1 | for i in 0 to array_length-1 loop
|
2 | tmp <= tmp + conv_integer(vec_value(i));
|
3 | end loop;
|
4 | SUM <= conv_std_logic_vector(tmp);
|
Bei der Forschleife bekomme ich nun folgende Fehlermeldung:
"Syntax error near "in"". Ob danach noch weitere Fehler kommen, konnte
ich leider noch nicht feststellen.
Das Ganze sieh jetzt wie folgt aus(Hier ist jetzt noch kein Übertrag
implementiert. ):
1 | library IEEE;
|
2 | use IEEE.STD_LOGIC_1164.ALL;
|
3 | use ieee.std_logic_arith.all;
|
4 | use ieee.std_logic_unsigned.all;
|
5 |
|
6 |
|
7 | entity COG is
|
8 | port (
|
9 | -- A, B : in std_logic_vector(7 downto 0);
|
10 | -- CI : in std_logic;
|
11 | SUM : out std_logic_vector(7 downto 0);
|
12 | -- CO : out std_logic);
|
13 | end COG;
|
14 |
|
15 | architecture Behavioral of COG is
|
16 |
|
17 |
|
18 | constant vec_value: table := ("00000000","00000001","00000010","00000010","00000010","00000110","00010010");
|
19 |
|
20 | signal tmp : integer := 0 ;
|
21 | signal array_length : std_logic_vector(vec_value'length downto 0);
|
22 |
|
23 | for i in 0 to array_length-1 loop
|
24 | tmp <= tmp + conv_integer(vec_value(i));
|
25 | end loop;
|
26 | SUM <= conv_std_logic_vector(tmp);
|
27 |
|
28 | end Behavioral;
|
Wäre um jeden Rat dankbar,
grüße,
Ralf