Ich dachte, mich schockt nichts mehr an VHDL, aber es kam anders:
1 | library ieee;
|
2 | use ieee.std_logic_1164.all;
|
3 | use std.textio.all;
|
4 |
|
5 | entity slv2str is
|
6 | end entity slv2str;
|
7 |
|
8 | architecture behavior of slv2str is
|
9 |
|
10 | function slv_to_str(vec : std_logic_vector) return string is
|
11 | variable temp : string(vec'left+1 downto 1) := (others =>
|
12 | 'X');
|
13 | begin
|
14 | for i in vec'reverse_range loop
|
15 | if (vec(i) = '1') then
|
16 | temp(i+1) := '1';
|
17 | elsif (vec(i) = '0') then
|
18 | temp(i+1) := '0';
|
19 | end if;
|
20 | end loop;
|
21 | return temp;
|
22 | end function;
|
23 |
|
24 | signal v : std_logic_vector(7 downto 0) := b"01001100";
|
25 |
|
26 | begin
|
27 |
|
28 | test : process is
|
29 | variable l : line;
|
30 | begin
|
31 | write(l, slv_to_str(v(7 downto 6)) & slv_to_str(v(5 downto 0)));
|
32 | writeline(output, l);
|
33 | wait;
|
34 | end process test;
|
35 |
|
36 | end architecture behavior;
|
$ vcom.exe -93 slv2str.vhd
Model Technology ModelSim XE III vcom 6.0a Compiler 2004.11 Nov 10
2004
-- Loading package standard
-- Loading package std_logic_1164
-- Loading package textio
-- Compiling entity slv2str
-- Compiling architecture behavior of slv2str
$ vsim -c work.slv2str
Reading C:/Programme/mxe/tcl/vsim/pref.tcl
# 6.0a
# vsim -c work.slv2str
# Loading c:\programme\mxe\win32xoem/../std.standard
# Loading c:\programme\mxe\win32xoem/../ieee.std_logic_1164(body)
# Loading c:\programme\mxe\win32xoem/../std.textio(body)
# Loading ./work.slv2str(behavior)
VSIM 1> run 10 ns
# 01XXXXXX001100
Was zur Hölle soll das??? Der Standard kann doch nicht allen Ernstes
erlauben, dass die ursprüngliche vectorgröße hier einen Einfluss hat?
Bekommt die Funktion nicht eine verkürzte Kopie des orig. Vectors? Wie
kriege ich hier die Kuh vom Eis?
Viele Grüße
Olaf