------------------------------------------------------------------------------
entity ent is
generic(
num: integer range 0 to 3 := 0
);
port(
clk: in mvl5w;
data: in mvl5w_vector(15 downto 0);
valid: in mvl5w;
kill: in mvl5w
);
end ent;
Architecture behavior of ent is
file outfile: text is out "hello" & string(num); -- doesn't work
begin
...
end behavior;
------------------------------------------------------------------------------
sorry if this is FAQ, but i couldn't find anything in the LRM or other
VHDL texts. of course i could pass in the number as a character or
string, but i'd rather not as it gets used in integer operations
later. i guess i could also write my own function...
advTHANKSance
--janaka
--
-----------------------------------------------------------------------------
| jwit...@phoenix.princeton.edu jan...@lucille.princeton.edu |
| jan...@ee.princeton.edu JWIT...@PUCC.bitnet m...@clarity.princeton.edu |
-----------------------------------------------------------------------------
These are not closely related types (see recent posting by me), so you can't
use a type conversion, as you tried.
You can write your own function, or use TextIO.
Here's a function for Naturals:
function cvString (N, L: Natural) return String
-- Accepts a number N to convert into a string of length L. If the resulting
-- string is too small, you get the least-significant digits of N in the
-- returned string.
is
variable Temp: Natural := N;
variable Result: String(1 to L) := (others => ' ');
begin
for i in Result'reverse_range loop
Result(i) := Character'Val((Temp mod 10) + Character'Pos('0'));
Temp := Temp/10;
exit when Temp = 0;
end loop;
return Result;
end cvString;
Extend to integers if you're going negative.
Here's a function to tell you what L should be for a given N:
function Log10 (N: Natural) return Natural is
variable Temp: Natural := N;
variable Result: Natural := 1;
begin
loop
Temp := Temp/10;
exit when Temp = 0;
Result := Result + 1;
end loop;
return Result;
end Log10;
--Paul
--
Paul Menchini email: me...@rock.concert.net "Pay no attention to
2 Davis Drive voice: 919-990-9506 that man behind the
P.O. Box 13036 fax: 919-990-8561 curtain!"
RTP, NC 27709-3036 -- The Wizard of Oz