Altera_Forum
Honored Contributor
17 years agoArray Multiplying CPU
I coded the following as a CPU to multiply two arrays and I don't get the proper output. I do get some output but it's not correct. Any ideas are appreciated:
--------------------------------------------------------------------------------------------- LIBRARY ieee; USE ieee.std_logic_1164.ALL; USE ieee.std_logic_arith.ALL; USE ieee.std_logic_signed.ALL; ENTITY cpu_test IS PORT (clk: IN std_logic; output: OUT std_logic_vector(7 downto 0)); END cpu_test; ARCHITECTURE rtl OF cpu_test IS SIGNAL north, west: std_logic_vector(3 downto 0); SIGNAL north_int, west_int: signed(3 downto 0); SIGNAL sum_int, stored_int: signed(7 downto 0); SIGNAL result_int: signed(7 downto 0); SIGNAL result: std_logic_vector(7 downto 0); SIGNAL stored: std_logic_vector(7 downto 0); TYPE matrix IS ARRAY (3 downto 0) OF std_logic_vector(3 downto 0); CONSTANT matrix_A: matrix :=((X"9",X"8",X"7",X"6")); CONSTANT matrix_B: matrix :=((X"5",X"4",X"3",X"2")); BEGIN PROCESS (clk) VARIABLE matrix_result: std_logic_vector(7 downto 0) := X"00"; VARIABLE addr: INTEGER RANGE 0 TO 4 := 0; BEGIN IF (addr < 4) THEN west <= matrix_A(addr); north <= matrix_B(addr); stored <= matrix_result; IF (clk'EVENT AND clk = '1') THEN north_int <= SIGNED(north); west_int <= SIGNED(west); sum_int <= north_int * west_int; stored_int <= SIGNED(stored); result_int <= stored_int + sum_int; result <= STD_LOGIC_VECTOR(result_int); END IF; matrix_result := result; output <= matrix_result; addr := addr + 1; END IF; END PROCESS; END rtl; --------------------------------------------------------------------- Something is wrong with the way I'm thinking about this design, but I'm not sure what.