Nicolas said:
Is there a way to force the character string to a fixed length when
using integer'image attribute?
See the function fix below
-- Mike Treseler
----------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use std.textio.all;
entity fix_str is
end entity fix_str;
-- Thu Apr 13 09:39:48 2006 M. Treseler
architecture sim of fix_str is
begin
what
rocess is
----------------------------------------------
function fix
( arg_str : string;
ret_len_c : natural := 10;
fill_char_c : character := '0' )
return string is
variable ret_v : string (1 to ret_len_c);
constant pad_len_c : integer := ret_len_c - arg_str'length ;
variable pad_v : string (1 to abs(pad_len_c));
begin
if pad_len_c < 1 then
ret_v := arg_str(ret_v'range);
else
pad_v := (others => fill_char_c);
ret_v := pad_v & arg_str;
end if;
return ret_v;
end fix;
----------------------------------------------
procedure print
(str1 : in string := "") is
constant newline_c : string := (1 => LF);
constant line_c : string := newline_c & str1;
begin
write(std.textio.output, line_c);
end procedure print;
----------------------------------------------
begin
print( fix("1"));
print( fix("123"));
print( fix("1234567890"));
print( fix("1234567890123"));
print( fix(integer'image(98765)));
print( fix(integer'image(98765),8));
print( fix(integer'image(98765),8,'_'));
wait;
end process what;
end architecture sim;
----------------------------------------------
--vsim -c fix_str
--VSIM 1> run
--# 0000000001
--# 0000000123
--# 1234567890
--# 1234567890
--# 0000098765
--# 00098765
--# ___98765
--VSIM 2>