Operators and attributes_L7

Download Report

Transcript Operators and attributes_L7

Operators
•
•
•
•
•
•
•
Assignment Operators
Logical Operators
Relational Operators
Shift Operators
Adding Operators
Multiplying Operators
Miscellaneous Operators
9/23/2006
DSD,USIT,GGSIPU
1
Assignment Operators
• Used to assign values to signals, variables
and constants.
<=
Used to assign a value to a Signal
:=
Used to assign a value to a variable,
constant, or Generic
Must be the same size and type
=>
Used to assign values to individual
vector elements or with OTHERS.
9/23/2006
DSD,USIT,GGSIPU
2
Logical Operators
• The seven Logical Operators
–
–
–
–
–
–
–
9/23/2006
AND
OR
NAND are not associative
NOR are not associative
XOR
XNOR
NOT ; highest precedence over the others
DSD,USIT,GGSIPU
3
Relational Operator
•
•
•
•
•
•
•
=
Equality
/=
inequality
<
<=
>
>=
Must be one-dimensional discrete array of the
same type.
9/23/2006
DSD,USIT,GGSIPU
4
Shift Operators
•
•
•
•
•
•
Sll
Srl
Sla
Sra
Rol
Ror
9/23/2006
Shift left logical
Shift right logical
Shift left arithmetic
Shift right arithmetic
Rotate left
Rotate Right
DSD,USIT,GGSIPU
5
• A = 10101100
• B <= rol a, -2;
• B = 10110011
• B <= 00111011
• B <= sla a, 3
b <= 01100000
• B<= sra a, 2
b <= 11101011
• RLC : Rotate Left with carry
• RRC : Rotate Right with carry
• Carry : 1
B <= Rlc a, 2
B <= 10110011
carry : 0
9/23/2006
DSD,USIT,GGSIPU
6
Adding Operators
• +
• • &
•
•
•
•
•
addition
subtraction
Concatenation
Example:
A = 1010
B = 1000
C <= a & b; c = 10101000
C <= b & a; c := 10001010
9/23/2006
DSD,USIT,GGSIPU
7
Multiplying Operators
•
•
•
•
*
/
Mod
Rem
9/23/2006
Multiplication
Division
modulus
Remainder
DSD,USIT,GGSIPU
8
Miscellaneous Operators
• Abs
• **
• Not
9/23/2006
Absolute
Exponentiation
negation
DSD,USIT,GGSIPU
9
Attributes
• An attributes is a value, function, type,
range, signal or a constant that may be
associated with one or more names within a
VHDL description.
– Two types of attributes
• User defined attributes
• Predefined attributes
9/23/2006
DSD,USIT,GGSIPU
10
Classes of attributes
1. Value attributes
2. Function attributes
: Return a constant value
: Call a function that return a value
3.
4.
5.
: Creates a new implicit signal
: Return a type
: Returns a range
Signal Attributes
Type Attributes
Range attributes
To use a attribute the “’” (apostrophe) construct must
be employed
9/23/2006
DSD,USIT,GGSIPU
11
Type Attributes
• T’Base Returns the base type of datatype it is
attached to
example:
Natural’base returns integer
• T’Left
Returns left value specified in type
declaration
Example:
Integer’Left is –2147483647
Bit’left is ‘0’
9/23/2006
DSD,USIT,GGSIPU
12
• T’right Returns right value specified in
type declaration
Example:
Integer’right is 2147483647
bit’right is ‘1’
• T’high Returns largest value specified in
declaration
Example:
Type bit8 is 255 downto 0
bit8’high is 255
9/23/2006
DSD,USIT,GGSIPU
13
• T’low Returns smallest value specified in
declaration
Example:
Type bit8 is 255 downto 0;
bit8’low is 0;
• T’pos(x) Returns position number of
argument in type (first position is 0)
Example:
Type color is (red,green, blue, orange);
color’pos(green) is 1;
9/23/2006
DSD,USIT,GGSIPU
14
• T’val(x) Returns value in type at specified
position number
Example:
Type color is (red,green, blue, orange);
color’val(3) is orange;
• T’succ(x)
Returns the successor to the
value passed in
Example:
Type color is (red,green, blue, orange);
color’succ(green) is blue;
9/23/2006
DSD,USIT,GGSIPU
15
• T’pred(x)
Returns the predecessor to
the value passed in
Example:
Type color is (red,green, blue, orange);
color’pred(blue) is green;
• T’leftof(x)
Returns the value to the left
of the value passed in
Example:
Type color is (red,green, blue, orange);
color’leftof(blue) is green
9/23/2006
DSD,USIT,GGSIPU
16
• T’rightof(x) Returns the value to the right
of the value passed in
Example:
Type color is (red,green,blue,orange);
color’rightof(blue) is orange;
Type s is (1,0,0,1,0,1)
S’rightof(1)
9/23/2006
DSD,USIT,GGSIPU
17
Type a_type is array(0 to 3, 7 downto 0) of bit;
• A’left(n)
Returns left array bound of
selected index range
Example:
a_type’left(1) is 0
a_type’left(2) is 7
• A’right(n) Returns right array bound of selected
index range
Example:
a_type’right(1) is 3
a_type’right(2) is 0
9/23/2006
DSD,USIT,GGSIPU
18
Type a_type is array(0 to 3, 7 downto 0) of bit;
• A’high(n) Returns largest array bound value of
selected index range
Example:
a_type’high(1) is 3
a_type’high(2) is 7
• A’low(n) Returns smallest array bound value of
selected index range
Example:
a_type’low(1) is 0
a_type’low(2) is 0
9/23/2006
DSD,USIT,GGSIPU
19
Type a_type is array(0 to 3, 7 downto 0) of bit;
• A’range
Returns selected index range
Example:
a_type’range(1) is 0 to 3
a_type’range(2) is 7 downto 0
• A’reverse_range(n) Returns selected index
range reversed
Example:
a_type’reverse_range(1) 3 downto 0
a_type’reverse_range(2) 0 to 7;
9/23/2006
DSD,USIT,GGSIPU
20
Type a_type is array(0 to 3, 7 downto 0) of bit;
• A’length(n)
index range
Returns size of selected
Example:
a_type’length(1) is 4
a_type’length(2) is 8.
9/23/2006
DSD,USIT,GGSIPU
21
Signal attributes
• S’event
– Function returning a boolean that identifies if
signal S has a new value assigned onto this
signal (I.e. value is different that last value)
– Returns TRUE when an event occurs on s.
– If clk’event then …….– if clk just changed in
value than…
– Wait until clk’event and clk=‘1’ ;-- rising edge
of clock
9/23/2006
DSD,USIT,GGSIPU
22
Signal attribute (cont..)
• S’stable
– Implicit signal of Boolean type. This implicit
signal has the value TRUE when an event
(change in value) has not occurred on signal S
for T time units and the value FALSE
otherwise. If time is omitted, it defaults to 0ns.
– Returns TRUE if no event has occurred on s
– If s’stable(40ns) then – met set up time
9/23/2006
DSD,USIT,GGSIPU
23
S’active
• S’active
– Function returning a boolean that identifies if
signal S had a new assignment made onto it
(whether the value of the assignment is the
SAME or DIFFERENT).
– Returns TRUE if s = ‘1’
– If s’active then…….– New assignment of S
– Wait on s’active;
– Wait until s’active;
9/23/2006
DSD,USIT,GGSIPU
24
Signal attribute (cont..)
• S’quiet <time>
– This implicit signal has the value TRUE when the
signal has been quiet (I.e. no activity or signal
assignment) for T time units, and the value FALSE
otherwise. If time is omitted, it defaults to 0ns.
– Returns TRUE if no event has occurred during the time
specified
– If s’quiet(40ns) then – Really quiet, not even an
assignment of the same value during the last T time
units.
9/23/2006
DSD,USIT,GGSIPU
25
Signal attributes (cont..)
• S’Last_event
– Function returning the amount of time that has elapsed
since the last event (change in value) occurred on signal
S. If there was no previous event, it returns Time’high
(The maximum value for time)
– Returns the time elapsed since last event
– Variable : TsinceLastEvent:time;
– ….
– TsinceLastEvent :s’last_event;
9/23/2006
DSD,USIT,GGSIPU
26
• S’Last_active
– Returns the time elapsed since last s=‘1’
9/23/2006
DSD,USIT,GGSIPU
27
Signal attribute (cont.)
• S’last_value
– Returns the value of s before the last event
• S’transaction
– Signal of type bit that changes for every
transaction on s
• S’delayed<time>
– Signal same as s delayed by specified time
9/23/2006
DSD,USIT,GGSIPU
28
User-defined Attributes
• Syntax
• Attribute Declaration:
– ATTRIBUTE attribute_name: attribute_type;
• Attribute specification:
– ATTRIBUTE attribute_name of target_name : class is
value;
Where:
Attribute_type : any data type (bit,std_logic etc)
Class
: type, signal,function etc.
Value
: ‘0’, 27, “000101110” , etc
9/23/2006
DSD,USIT,GGSIPU
29
Generic
• Generic is a way of specifying a generic
parameter
– A static parameter that can be easily modified
and adapted to different applications.
– A generic statement, when employed must be
declared in the entity.
Syntax:
Generic (parameter_name : parameter_type:=
parameter_value);
9/23/2006
DSD,USIT,GGSIPU
30