User`s manual

Modeling memory in VHDL
ModelSim Xilinx Users Manual Tips and Techniques C-297
variable n : natural := 0;
variable failure : boolean := false;
begin
assert (xhigh - xlow + 1) <= 31
report "Range of sulv_to_natural argument exceeds
natural range"
severity error;
for i in xrange loop
n := n * 2;
case x(i) is
when 1 | H => n := n + 1;
when 0 | L => null;
when others => failure := true;
end case;
end loop;
assert not failure
report "sulv_to_natural cannot convert indefinite
std_ulogic_vector"
severity error;
if failure then
return 0;
else
return n;
end if;
end sulv_to_natural;
function natural_to_sulv(n, bits : natural) return
std_ulogic_vector is
variable x : std_ulogic_vector(bits-1 downto 0) :=
(others => 0);
variable tempn : natural := n;
begin
for i in xreverse_range loop
if (tempn mod 2) = 1 then
x(i) := 1;
end if;
tempn := tempn / 2;
end loop;
return x;
end natural_to_sulv;
end conversions;