File: prism-vhdl.html

package info (click to toggle)
node-prismjs 1.30.0%2Bdfsg%2B~1.26.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 19,220 kB
  • sloc: javascript: 27,628; makefile: 9; sh: 7; awk: 4
file content (92 lines) | stat: -rw-r--r-- 3,009 bytes parent folder | download | duplicates (3)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<h2>Comments</h2>
<pre><code>-- I am a comment
I am not</code></pre>

<h2>Literals</h2>
<pre><code>constant FREEZE : integer := 32;
constant TEMP : real := 32.0;
A_INT &lt;= 16#FF#;
B_INT &lt;= 2#1010_1010#;
MONEY := 1_000_000.0;
FACTOR := 2.2E-6;
constant DEL1 :time := 10 ns;
constant DEL2 :time := 2.27 us;
type MY_LOGIC is ('X','0','1','Z');
type T_STATE is (IDLE, READ, END_CYC);
signal CLK : MY_LOGIC := '0';
signal STATE : T_STATE := IDLE;
constant FLAG :bit_vector(0 to 7) := "11111111";
constant MSG : string := "Hello";
BIT_8_BUS &lt;= B"1111_1111";
BIT_9_BUS &lt;= O"353";
BIT_16_BUS &lt;= X"AA55";
constant TWO_LINE_MSG : string := "Hello" & CR & "World";</code></pre>

<h2>Full example</h2>
<pre><code>-- example code from: http://www.csee.umbc.edu/portal/help/VHDL/samples/samples.html
library IEEE;
use IEEE.std_logic_1164.all;

entity fadd is               -- full adder stage, interface
  port(a    : in  std_logic;
       b    : in  std_logic;
       cin  : in  std_logic;
       s    : out std_logic;
       cout : out std_logic);
end entity fadd;

architecture circuits of fadd is  -- full adder stage, body
begin  -- circuits of fadd
  s &lt;= a xor b xor cin after 1 ns;
  cout &lt;= (a and b) or (a and cin) or (b and cin) after 1 ns;
end architecture circuits; -- of fadd

library IEEE;
use IEEE.std_logic_1164.all;
entity add32 is             -- simple 32 bit ripple carry adder
  port(a    : in  std_logic_vector(31 downto 0);
       b    : in  std_logic_vector(31 downto 0);
       cin  : in  std_logic;
       sum  : out std_logic_vector(31 downto 0);
       cout : out std_logic);
end entity add32;

architecture circuits of add32 is
  signal c : std_logic_vector(0 to 30); -- internal carry signals
begin  -- circuits of add32
  a0: entity WORK.fadd port map(a(0), b(0), cin, sum(0), c(0));
  stage: for I in 1 to 30 generate
             as: entity WORK.fadd port map(a(I), b(I), c(I-1) , sum(I), c(I));
         end generate stage;
  a31: entity WORK.fadd port map(a(31), b(31), c(30) , sum(31), cout);
end architecture circuits;  -- of add32

use STD.textio.all;
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_textio.all;

entity signal_trace is
end signal_trace;

architecture circuits of signal_trace is
  signal a:    std_logic_vector(31 downto 0) := x"00000000";
  signal b:    std_logic_vector(31 downto 0) := x"FFFFFFFF";
  signal cin:  std_logic := '1';
  signal cout: std_logic;
  signal sum:  std_logic_vector(31 downto 0);
begin  -- circuits of signal_trace
  adder: entity WORK.add32 port map(a, b, cin, sum, cout); -- parallel circuit

  prtsum: process (sum)
            variable my_line : LINE;
            alias swrite is write [line, string, side, width] ;
          begin
            swrite(my_line, "sum=");
            write(my_line, sum);
            swrite(my_line, ",  at=");
            write(my_line, now);
            writeline(output, my_line);
          end process prtsum;

end architecture circuits; -- of signal_trace</code></pre>