Download IEEE Numeric-STD Package and the VHDL Alias | ECE 371 and more Assignments Microprocessors in PDF only on Docsity!
Laboratory Assignment #7 IEEE NUMERIC_STD
Package and the VHDL
ALIAS
Spring 2009
ECE 371: Microprocessor Systems Department of Electrical and Computer EngineeringSchool of Engineering, Mathematics, and Science
Purdue University – Calumet
Arithmetic VHDL Packages
-^ numeric_std^ •^ The standard IEEE arithmetic VHDL package •^ std_logic_arith •^ std_logic_unsigned •^ std_logic_signed •^ std_logic_signed^ •^ Non-standard IEEE arithmetic VHDL package•^ Developed by Synopsys while IEEE crafted Link: http://www.eda.org/rassp/vhdl/models/standards/numeric_std.vhd
numeric_std
-^ Older designs utilize these packages so need to be familiar
NUMERIC_STD
Package
Defined Types
-^ UNSIGNED
Type
-^ Represents unsigned
number in vector form based on base element
type^ STD_LOGIC • Range of Values (assuming n-bits): 0 to 2
n^ – 1
-^ Example
:^ SIGNAL^
count :^
UNSIGNED
(3^ DOWNTO
Range of Values: 0 to +
-^ SIGNED
Type • Represents signed
number in vector form based on base element
type^ STD_LOGIC • Two’s complement representation; MSB is sign-bit.• Range of Values (assuming n-bits): -
n-1^ n-1^ to 2– 1
-^ Example
:^ SIGNAL^
count :^
SIGNED(
DOWNTO^
Range of Values: -8 to +
Link:^ http://www.eda.org/rassp/vhdl/models/standards/numeric_std.vhd
VHDL^ NUMERIC_STD
Functions
-^ Provides functions to perform arithmetic operations•^ Example
: Reading the
numeric_std.vhd
file?
FUNCTION^
“+” (L:^ UNSIGNED
; R:^ NATURAL
)^ RETURN UNSIGNED;
-^ Function defines the addition operator
- •^ The “left” operand is of type
UNSIGNED
-^ The “right” operand is of type
NATURAL
-^ The return type is type
UNSIGNED UNSIGNED = UNSIGNED + NATURAL
Link:^ http://www.eda.org/rassp/vhdl/models/standards/numeric_std.vhd
Comparison Functions^ Argument and Return Types
Operation^
Left Arg.^ Right Arg.^ Return Value
Greater Than? (“>”)Greater Than Equal To? (“>=”)Less Than? (“<”)Less Than or Equal To? (“<=”)Equal? (“=”) Not Equal?^ (“/=”)
SIGNED^
SIGNED^
BOOLEAN
INTEGER^
SIGNED^
BOOLEAN
SIGNED^
INTEGER^
BOOLEAN
UNSIGNED^
UNSIGNED^
BOOLEAN
Not Equal?^ (“/=”)
UNSIGNED^
NATURAL^
BOOLEAN
NATURAL^
UNSIGNED^
BOOLEAN
Note 1:^ NATURAL
is subtype of^
INTEGER^ which includes values in rage from 0 to 2
Note 2:^ POSITIVE
is subtype of^
INTEGER^ which includes values in range from 1 to 2
Note 3 : Return value width is not valid here since return value is
BOOLEAN
Link:^ http://www.eda.org/rassp/vhdl/models/standards/numeric_std.vhd
Logic, Shift, Rotate, and Resize Func.
Argument and Return Types
Operation^
Argument^
Count Arg.^
Return^ Return Width
Shift Left (SHIFT_LEFT)Shift Right (SHIFT_RIGHT)Rotate Left (ROTATE_LEFT)Rotate Right (ROTATE_RIGHT)
UNSIGNED^
NATURAL^
UNSIGNED^
Unsigned Arg.
SIGNED^
NATURAL^
SIGNED^
Signed Arg.
Note:^ How to do arithmetic vs. logical shifting?^ Operation^
Left Arg.^ Right Arg.^
Return Value^
Return Width
Operation Link:^ http://www.eda.org/rassp/vhdl/models/standards/numeric_std.vhd
Left Arg.
Right Arg.
Return Value
Return Width
AND, OR, NAND,NOR, XOR, XNOR
SIGNED^
SIGNED^
SIGNED^
Signed Arg.
UNSIGNED^
UNSIGNED^
UNSIGNED^
Unsigned Arg.
NOT (“NOT”)^
UNSIGNED^
UNSIGNED^
UNSIGNED^
Unsigned Arg.
SIGNED^
SIGNED^
SIGNED^
Signed Arg.
RESIZE^
SIGNED^
NATURAL^
SIGNED^
Signed Arg.
UNSIGNED^
NATURAL^
UNSIGNED^
Unsigned Arg.
Note:^ Logical Operator Usage:
C^ <=^ A^ XOR
B;
Example 1
Parameterized Unsigned Adder With Cin and Cout LIBRARY^ IEEE; USE IEEE.STD_LOGIC_1164.
ALL;
USE IEEE.NUMERIC_STD.
ALL;
ENTITY^ unsigned_adder
IS
GENERIC( N :
POSITIVE
PORT( a, b :
IN^ STD_LOGIC_VECTOR
(N-^1 DOWNTO
cin^ :^ IN
STD_LOGIC
sum^ :^ OUT STD_LOGIC_VECTOR
(N-1^ DOWNTO
cout :^ OUT STD_LOGIC
END ENTITY
unsigned_adder;
ARCHITECTURE
behavior
OF^ unsigned_adder
IS
SIGNAL^ tempSum :
UNSIGNED
(N+1^ DOWNTO
BEGIN^ tempSum <=
UNSIGNED
('0‘ & a & ’1’) +
UNSIGNED
('0‘ & b & cin);
sum <=^ STD_LOGIC_VECTOR
(tempSum(N-
DOWNTO^ 0));
cout <= tempSum(N); END ARCHITECTURE
behavior;
Example 2 Parameterized Signed Adder with Cout
LIBRARY^ IEEE; USE^ IEEE.STD_LOGIC_1164.
ALL;
USE IEEE.NUMERIC_STD.
ALL;
ENTITY^ signed_adder
IS
GENERIC( N :
POSITIVE
PORT( a, b :
IN^ STD_LOGIC_VECTOR
(N-^1 DOWNTO
PORT( a, b :
IN^ STD_LOGIC_VECTOR
(N-^1 DOWNTO
sum^ :^ OUT STD_LOGIC_VECTOR
(N-1^ DOWNTO
cout :^ OUT STD_LOGIC
END ENTITY
signed_adder;
ARCHITECTURE
behavior
OF^ signed_adder
IS
SIGNAL^ tempSum :
SIGNED(N
DOWNTO^ 0);
BEGIN^ tempSum <=
SIGNED('0‘ & a) +
SIGNED('0‘ & b);
sum <=^ STD_LOGIC_VECTOR
(tempSum(N-
DOWNTO^ 0));
cout <= tempSum(N); END ARCHITECTURE
behavior;
Example 4 Parameterized Signed Multiply-Add Unit (MAU) LIBRARY^ IEEE; USE IEEE.STD_LOGIC_1164.
ALL;
USE^ IEEE.NUMERIC_STD.
ALL;
ENTITY^ mau_nbit
IS
GENERIC(^ A_SIZE
:^ POSITIVE
:=^ 4;
B_SIZE^ :^ POSITIVE
:=^4 );
B_SIZE^ :^ POSITIVE
:=^4 );
PORT(^ a^
:^ IN^ STD_LOGIC_VECTOR
(A_SIZE-^
DOWNTO^ 0);
b^ :^ IN
STD_LOGIC_VECTOR
(B_SIZE-^
DOWNTO^ 0);
c^ :^ IN
STD_LOGIC_VECTOR
(A_SIZE^ +^
B_SIZE–1^ DOWNTO
result^ :^ OUT
STD_LOGIC_VECTOR
(A_SIZE+B_SIZE–
DOWNTO^ 0));
END^ ENTITY
mau_nbit; ARCHITECTURE
behavior^
OF^ mau_nbit
IS
SIGNAL^ product
:^ SIGNED(A_SIZE+B_SIZE-
DOWNTO^ 0);
BEGIN^ product
<=^ SIGNED
(a)^ *^ SIGNED
(b); result^ <=^
STD_LOGIC_VECTOR
(product^ + SIGNED(c));
END^ ARCHITECTURE
behavior;
VHDL Aliases
•^ Provides an alternative name for existing objects^ –^ All objects can be aliased
except:
•^ loop parameters, labels, and generate parameters – do not define a new object • Shorthand^ for referencing complex slices• Shorthand^ for referencing complex slices • Syntax – ALIAS^ alias_name : alias_type
IS^ object_name;
•^ Examples^ ALIAS^
ASign :^ STD_LOGIC IS
A(31);
ALIAS^ rs :
STD_LOGIC_VECTOR
(4^ DOWNTO
0)^ IS
instr(^
DOWNTO^ 21);
ALIAS^ my_logic
IS^ IEEE.STD_LOGIC_1164.
STD_LOGIC
ALIAS^ my_nand
IS^ ASIC_LIB.ONE_MICRON.ND2;