Guest
I am designing a VHDL combinational block that takes in a list of 8
ASCII characters as input and replaces the non-numeral characters with a
dash '-', then rearranges the list to have the numerals on one side and
'-'s on the other.
Example input and output:
Input: d126r24! Output: ---12246
Source Code:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity module1 is
port (list1: IN string (1 to 8);
list2: OUT string (1 to 8));
end entity;
architecture behavior of module1 is
signal temp: string (1 to 8);
begin
process (list1)
variable a: integer:= 1;
variable b: integer:= 8;
variable c: string (1 to 8);
begin
for i in 1 to 8 loop
if ((list1(i) = '0') or (list1(i) = '1') or (list1(i) = '2') or (list1(i) = '3') or (list1(i) = '4') or (list1(i) = '5') or (list1(i) = '6') or (list1(i) = '7') or (list1(i) = '8') or (list1(i) = '9')) then
c(a):= list1(i);
a := a + 1;
else
c(b) := '-';
b := b - 1;
end if;
end loop;
temp <= c;
end process;
list2 <= temp;
end behavior;
TEST BENCH:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity tb_module1 is
end entity;
architecture behavior of tb_module1 is
component module1
port (list1: IN string (1 to 8);
list2: OUT string (1 to 8));
end component;
signal list1, list2: string (1 to 8);
begin
DUT: module1 port map (list1 => list1, list2 => list2);
process
begin
wait for 0 ns;
list1 <= "12345678";
wait for 10 ns;
list1 <= "001122nn";
wait for 10 ns;
end process;
end behavior;
ISSUE: codes compile fine but upon simulating I get a fatal error in modelsim:
"run
# ** Fatal: (vsim-3734) Index value 9 is out of range 1 to 8.
# Time: 10 ns Iteration: 1 Process: /tb_module1/DUT/line__15 File: C:/Modeltech_pe_edu_10.4a/examples/module1.vhd
# Fatal error in ForLoop loop at C:/Modeltech_pe_edu_10.4a/examples/module1.vhd line 23
#
# HDL call sequence:
# Stopped at C:/Modeltech_pe_edu_10.4a/examples/module1.vhd 23 ForLoop loop"
I cannot understand how this index error is happening. Please help!
ASCII characters as input and replaces the non-numeral characters with a
dash '-', then rearranges the list to have the numerals on one side and
'-'s on the other.
Example input and output:
Input: d126r24! Output: ---12246
Source Code:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity module1 is
port (list1: IN string (1 to 8);
list2: OUT string (1 to 8));
end entity;
architecture behavior of module1 is
signal temp: string (1 to 8);
begin
process (list1)
variable a: integer:= 1;
variable b: integer:= 8;
variable c: string (1 to 8);
begin
for i in 1 to 8 loop
if ((list1(i) = '0') or (list1(i) = '1') or (list1(i) = '2') or (list1(i) = '3') or (list1(i) = '4') or (list1(i) = '5') or (list1(i) = '6') or (list1(i) = '7') or (list1(i) = '8') or (list1(i) = '9')) then
c(a):= list1(i);
a := a + 1;
else
c(b) := '-';
b := b - 1;
end if;
end loop;
temp <= c;
end process;
list2 <= temp;
end behavior;
TEST BENCH:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity tb_module1 is
end entity;
architecture behavior of tb_module1 is
component module1
port (list1: IN string (1 to 8);
list2: OUT string (1 to 8));
end component;
signal list1, list2: string (1 to 8);
begin
DUT: module1 port map (list1 => list1, list2 => list2);
process
begin
wait for 0 ns;
list1 <= "12345678";
wait for 10 ns;
list1 <= "001122nn";
wait for 10 ns;
end process;
end behavior;
ISSUE: codes compile fine but upon simulating I get a fatal error in modelsim:
"run
# ** Fatal: (vsim-3734) Index value 9 is out of range 1 to 8.
# Time: 10 ns Iteration: 1 Process: /tb_module1/DUT/line__15 File: C:/Modeltech_pe_edu_10.4a/examples/module1.vhd
# Fatal error in ForLoop loop at C:/Modeltech_pe_edu_10.4a/examples/module1.vhd line 23
#
# HDL call sequence:
# Stopped at C:/Modeltech_pe_edu_10.4a/examples/module1.vhd 23 ForLoop loop"
I cannot understand how this index error is happening. Please help!