Hello, I find that GHDL is a great tool, thank you for your efforts!
I might be missing something as far as language semantics that GHDL supports, but I am getting the following error:
Floating point exception: 8
When I try to use this function:
function to_hstring(
a : in std_logic_vector) return string is
--- Locals to make the indexing easier
constant a_norm: std_logic_vector(a'length-1 downto 0) := a;
variable result: string (1 to a'length/4);
--- A subtype to keep the VHDL compiler happy
--- (the rules about data types in a CASE are quite strict)
subtype slv4 is std_logic_vector(3 downto 0);
begin
assert (a'length mod 4) = 0
report "SLV must be a multiple of 4 bits"
severity FAILURE;
for i in result'range loop
case slv4'(a_norm(i*4+3 downto i*4)) is
when "0000" => result(i) := '0';
when "0001" => result(i) := '1';
when "0010" => result(i) := '2';
when "0011" => result(i) := '3';
when "0100" => result(i) := '4';
when "0101" => result(i) := '5';
when "0110" => result(i) := '6';
when "0111" => result(i) := '7';
when "1000" => result(i) := '8';
when "1001" => result(i) := '9';
when "1010" => result(i) := 'a';
when "1011" => result(i) := 'b';
when "1100" => result(i) := 'c';
when "1101" => result(i) := 'd';
when "1110" => result(i) := 'e';
when "1111" => result(i) := 'f';
when others => result(i) := 'X';
end case;
end loop;
return result;
end;
Can someone give me some ideas as to why this code is failing? I am trying to convert a std_logic_vector to a string to report to the terminal.
Thanks!
-Dustin B
Well I restructured my Vector to ASCII function and do not get this error during ellaboration anymore. Here is the new code that runs fine:
function toascii(
a : in std_logic_vector) return string is
--- Locals to make the indexing easier
constant a_norm : std_logic_vector(a'length-1 downto 0) := a;
constant len : integer := a'length/4;
variable result : string (1 to a'length/4);
variable nibble : std_logic_vector(3 downto 0);
begin
assert (a'length mod 4) = 0
report "SLV must be a multiple of 4 bits"
severity FAILURE;
for i in 1 to len loop
-- Branch at beginning of loop
if( i = 1 ) then
nibble := a_norm(3 downto 0);
else
nibble := a_norm((i-1)*4+3 downto (i-1)*4);
end if;
-- Convert
case nibble is
when "0000" => result(len-i+1) := '0';
when "0001" => result(len-i+1) := '1';
when "0010" => result(len-i+1) := '2';
when "0011" => result(len-i+1) := '3';
when "0100" => result(len-i+1) := '4';
when "0101" => result(len-i+1) := '5';
when "0110" => result(len-i+1) := '6';
when "0111" => result(len-i+1) := '7';
when "1000" => result(len-i+1) := '8';
when "1001" => result(len-i+1) := '9';
when "1010" => result(len-i+1) := 'a';
when "1011" => result(len-i+1) := 'b';
when "1100" => result(len-i+1) := 'c';
when "1101" => result(len-i+1) := 'd';
when "1110" => result(len-i+1) := 'e';
when "1111" => result(len-i+1) := 'f';
when others => result(len-i+1) := 'X';
end case;
end loop;
return result;
end function toascii;