If you are going to put this on a Xilinx CPLD or FPGA, then you will need to replace the
for loops with clocked counters. If
explicit clock conditioning is
missing, sequential code happens in an "instant" of time.
The synthesis software will not allow "in-place" updates of "variables" unless it is conditioned by a clock. In fact, there are no variables in the generated design. There is no computer, CPU, or MCU that "runs" VHDL. There are only registers, which are
generated by the "compiler", and they must be explicitly clocked in VHDL.
Only the simulator will act like a computer. The computer-like simulator code (the test bench) must not be part of the primary design code.
Just to show how radically you must change your thinking, the following shows how to sequentially read a 1024 x 8 ROM. Notice there are no
for loops, yet it will read every byte in the external ROM and output the data in sequence on the data_out pins.
Code:
-- "library" and "use" are cookie-cutter code generated by ISE
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity ROM_READER is
port (
data_in : in std_logic_vector (7 downto 0);
data_out : out std_logic_vector (7 downto 0);
addr_out : out std_logic_vector (9 downto 0)
);
end ROM_READER;
architecture Behavioral of ROM_READER is
signal addr_counter : std_logic_vector (9 downto 0);
begin
-- address counter
-- changes on each "tick" of the clock signal "clk"
process (clk)
begin
if rising_edge(clk) then
addr_counter <= addr_counter + 1;
end if;
end process;
-- output the contents of the address counter
-- addr_out is connected to the ROM address pins
addr_out <= addr_counter;
-- change output at clock edge
-- because we are capturing data in a register, the data from the ROM
-- shows up on data_out delayed by one clock cycle
-- data_in is connected to ROM data out pins
process (clk)
begin
if rising_edge(clk) then
data_out <= data_in;
end if;
end process;
end Behavioral;