Professional Documents
Culture Documents
VHDL
VHDL
signal
attributes
arrays and records
variables
functions and procedures
assertions
packages
Jon Turner
Signal Attributes
For
xleft=15, xright=0
these are referred to as attributes of x
other attributes include xhigh (=15), xlow (=0),
xrange (=15 downto 0) and xlength (=16)
Signal
This
Arrays of std_logic_vectors
-- using these declarations
subtype word is std_logic_vector(wordSize-1 downto 0);
type regFileTyp is array(0 to regFileSize-1) of word;
signal reg: regFileType;
-- we can write things like
reg(2) <= reg(1) + reg(4);
reg(3 downto 0) <= reg(7 downto 4);
reg(3)(5) <= 1;
reg(int(x)) <= reg(int(y)) -- int() converts to integer
Synthesizer
Defining Records
-- with these definitions
type entryType is record
valid: std_logic;
key, value: word
end record entryType;
constant tableSize: integer := 8;
type tableTyp is array(0 to tableSize-1) of entryType;
signal table: tableType
-- we can write
table(2).key <= table(1).value
if table(0).valid = 1 then
table(5) <= (1, xabcd, x0123);
end if;
Review Questions
1.
2.
3.
Variables
VHDL
-- assignment to variable y
b <= y;
y := y + x"10";
c <= y;
-- equivalent code segment without variables
a <= x"3a";
b <= a + x"01";
c <= (a+x"01") + x"10";
To
Functions
Functions
Each
Procedures
Procedures
Procedure
Assertions
Assertion
Add
Packages
Packages
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_arith.all;
use IEEE.std_logic_unsigned.all;
package commonDefs is
constant wordsize: integer := 16;
constant nBtn: integer := 4;...
subtype word is std_logic_vector(wordSize-1 downto 0);
subtype buttons is std_logic_vector(nBtn-1 downto 0);...
function int(d: std_logic_vector) return integer;
end package commonDefs;
library IEEE; ...
package body commonDefs is
function int(d: std_logic_vector) return integer is
begin return conv_integer(unsigned(d)); end function int;
end package body commonDefs;
Typically
package body
with function,
procedure
definitions
Exercises
1. Write a VHDL declaration for an array
of records, where the index range for
the record is the same as the index
range for a std_logic_vector, called z.
Each record in your array should have
two fields; field A is a std_logic_vector
with a descending range that has the
same limits as z, field B is a
std_logic_vector with an ascending
range that has the same limits as z.
Solutions
1.type recTyp: record is
A: std_logic_vector(zhigh
downto zlow);
B: std_logic_vector(zlow
to zhigh);
end record;
type recArray: array(zrange)
of recType;
2. The first assignment to x has no effect,
so the new value of x is a+x2,
where a=yx3=x4; so the new
value of x is x6.
The new value of y is a+x,
where a=x+y=xb, so the new value
of y is xf.
3.procedure minMax(
a, b: in SLV(7 downto 0);
x, y: out SLV(7 downto 0))
is begin
if a < b then
x := a; y := b;
else
x := b; y := a;
end if;
end procedure minMax;