blob: 4004b916bc5fd5a5585b5f009be3b2fff29167d7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity arr10 is
port (val : std_logic_vector(3 downto 0);
res : out natural);
end arr10;
architecture behav of arr10 is
function find (s : string; c : character) return natural is
begin
for i in s'range loop
if s (i) = c then
return i;
end if;
end loop;
return 0;
end find;
constant str1 : string := "hello world";
constant pos1 : natural := find (str1, 'w');
alias str2 : string (str1'length downto 1) is str1;
constant pos2 : natural := find (str2, 'w');
begin
assert pos1 = 7;
assert pos2 = 5;
res <= pos1;
end behav;
|