Debian Codegraph @

examples/prism-vhdl.html

raw symbols SCIP
1 <h2>Comments</h2>
2 <pre><code>-- I am a comment
3 I am not</code></pre>
4
5 <h2>Literals</h2>
6 <pre><code>constant FREEZE : integer := 32;
7 constant TEMP : real := 32.0;
8 A_INT &lt;= 16#FF#;
9 B_INT &lt;= 2#1010_1010#;
10 MONEY := 1_000_000.0;
11 FACTOR := 2.2E-6;
12 constant DEL1 :time := 10 ns;
13 constant DEL2 :time := 2.27 us;
14 type MY_LOGIC is ('X','0','1','Z');
15 type T_STATE is (IDLE, READ, END_CYC);
16 signal CLK : MY_LOGIC := '0';
17 signal STATE : T_STATE := IDLE;
18 constant FLAG :bit_vector(0 to 7) := "11111111";
19 constant MSG : string := "Hello";
20 BIT_8_BUS &lt;= B"1111_1111";
21 BIT_9_BUS &lt;= O"353";
22 BIT_16_BUS &lt;= X"AA55";
23 constant TWO_LINE_MSG : string := "Hello" & CR & "World";</code></pre>
24
25 <h2>Full example</h2>
26 <pre><code>-- example code from: http://www.csee.umbc.edu/portal/help/VHDL/samples/samples.html
27 library IEEE;
28 use IEEE.std_logic_1164.all;
29
30 entity fadd is -- full adder stage, interface
31 port(a : in std_logic;
32 b : in std_logic;
33 cin : in std_logic;
34 s : out std_logic;
35 cout : out std_logic);
36 end entity fadd;
37
38 architecture circuits of fadd is -- full adder stage, body
39 begin -- circuits of fadd
40 s &lt;= a xor b xor cin after 1 ns;
41 cout &lt;= (a and b) or (a and cin) or (b and cin) after 1 ns;
42 end architecture circuits; -- of fadd
43
44 library IEEE;
45 use IEEE.std_logic_1164.all;
46 entity add32 is -- simple 32 bit ripple carry adder
47 port(a : in std_logic_vector(31 downto 0);
48 b : in std_logic_vector(31 downto 0);
49 cin : in std_logic;
50 sum : out std_logic_vector(31 downto 0);
51 cout : out std_logic);
52 end entity add32;
53
54 architecture circuits of add32 is
55 signal c : std_logic_vector(0 to 30); -- internal carry signals
56 begin -- circuits of add32
57 a0: entity WORK.fadd port map(a(0), b(0), cin, sum(0), c(0));
58 stage: for I in 1 to 30 generate
59 as: entity WORK.fadd port map(a(I), b(I), c(I-1) , sum(I), c(I));
60 end generate stage;
61 a31: entity WORK.fadd port map(a(31), b(31), c(30) , sum(31), cout);
62 end architecture circuits; -- of add32
63
64 use STD.textio.all;
65 library IEEE;
66 use IEEE.std_logic_1164.all;
67 use IEEE.std_logic_textio.all;
68
69 entity signal_trace is
70 end signal_trace;
71
72 architecture circuits of signal_trace is
73 signal a: std_logic_vector(31 downto 0) := x"00000000";
74 signal b: std_logic_vector(31 downto 0) := x"FFFFFFFF";
75 signal cin: std_logic := '1';
76 signal cout: std_logic;
77 signal sum: std_logic_vector(31 downto 0);
78 begin -- circuits of signal_trace
79 adder: entity WORK.add32 port map(a, b, cin, sum, cout); -- parallel circuit
80
81 prtsum: process (sum)
82 variable my_line : LINE;
83 alias swrite is write [line, string, side, width] ;
84 begin
85 swrite(my_line, "sum=");
86 write(my_line, sum);
87 swrite(my_line, ", at=");
88 write(my_line, now);
89 writeline(output, my_line);
90 end process prtsum;
91
92 end architecture circuits; -- of signal_trace</code></pre>