title: VHDL integer to string
body: <p>Imagine you wanted to convert integers to strings in VHDL to display on a VGA monitor. You can't use ieee 2008 standard though because you have to use xilinx ISE 14.7. I have the following code for converting an integer type to a string type but I get "Non-static loop limit exceeded" errors for the while loop and in the for loop:</p>
  
  <pre><code>-- convert integer to string using specified base
  -- (adapted from Steve Vogwell's posting in comp.lang.vhdl)
  
  function str(int: integer; base: integer) return string is
  
  variable temp:      string(1 to 10);
  variable num:       integer;
  variable abs_int:   integer;
  variable len:       integer := 1;
  variable power:     integer := 1;
  
  begin
  
  -- bug fix for negative numbers
  abs_int := abs(int);
  
  num     := abs_int;
  
  while num &gt;= base loop                     -- Determine how many
    len := len + 1;                          -- characters required
    num := num / base;                       -- to represent the
  end loop ;                                 -- number.
  
  for i in len downto 1 loop                 -- Convert the number to
    temp(i) := chr(abs_int/power mod base);  -- a string starting
    power := power * base;                   -- with the right hand
  end loop ;                                 -- side.
  
  -- return result and add sign if required
  if int &lt; 0 then
     return '-'&amp; temp(1 to len);
   else
     return temp(1 to len);
  end if;
  
  end str;
  </code></pre>
  
  <p>I 'solved' the errors by morphing it to be this monstrosity:</p>
  
  <pre><code>-- convert integer to string using specified base
  -- (adapted from Steve Vogwell's posting in comp.lang.vhdl)
  
  function str(int: integer; base: integer) return string is
  
      variable temp:      string(1 to 9);
      variable num:       integer;
      variable abs_int:   integer;
      variable len:       integer := 1;
      variable power:     integer := 1;
  
      begin
  
      -- bug fix for negative numbers
      abs_int := abs(int);
  
      num     := abs_int;
  
      for i in 0 to 100 loop
          if (num &gt;= base) then                   -- Determine how many
            len := len + 1;                       -- characters required
            num := num / base;                    -- to represent the
          else                                    -- number.
              exit;
          end if;
      end loop ;                                 
  
      for i in 9 downto 1 loop                 -- Convert the number to
          if (i &lt;= len) then
              temp(i) := chr(abs_int/power mod base);  -- a string starting
              power := power * base;                   -- with the right hand
          else
              exit;
          end if;
      end loop ;                                 -- side.
  
      -- return result and add sign if required
      if int &lt; 0 then
         return '-'&amp; temp(1 to len);
       else
         return temp(1 to len);
      end if;
  
  end str;
  </code></pre>
  
  <p>Is there a non-retarded way to convert integers to strings?</p>