Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VHDL difference between => and <=

Tags:

syntax

vhdl

I keep forgetting and its difficult to search for the answer in a textbook or the Internet.

like image 253
Useless Intern Avatar asked Nov 02 '11 22:11

Useless Intern


2 Answers

Well, <= is assignment.

signal <= A or B;

=> is syntax used for case statements like so: (Stolen from http://www.cs.umbc.edu/portal/help/VHDL/sequential.html)

case  my_val  is
  when 1 =>  // This is kind of like how the : operator is used for switch in many languages
    a:=b;
  when 3 =>
    c:=d;
    do_it;
  when others =>
    null; // do nothing
end case;

end case;

=> can also be used in array assignments

myVector <= (1=>'1', OTHERS=>'0');  -- assigns ('0','1','0','0') to "myVector"

Source: http://www.eda.org/comp.lang.vhdl/html3/gloss_example.html

like image 191
Akron Avatar answered Sep 30 '22 03:09

Akron


A means to memorize when to use => and when to use <= is to think as follow.

"<=" as an assignment for signal as target (for variable it is ":=" ).

Examples:

y <= a + b + c; --y is a signal
v := a + b +c; --v is a variable

"=>" as mapping.

Example for component explicit mapping (recommended style IMHO):

my_instance : my_component
port map(
  port1 => my_signal1
);

Example for function explicit mapping (useful when parameters are not trivial):

my_signal <= my_function(parameter1 => something1, parameter2 => something2);

Example for array explicit mapping

type array_type is array(0 to 1) of std_logic_vector(7 downto 0);
constant my_array : array_type := (0 => x"AB", 1 => x"CD");

Example for record explicit mapping

type record_type is record
a : natural;
b : std_logic_vector(2 downto 0);
end record;
constant my_record: record_type := (a => 0, b => "101");

The advantage is this style allows you to do the mapping in the order of your choice (not necessarily the order in the definition of the component/function...) . Moreover in the particular case of array with only one item, it is required.

Finally, with the "=>", the keyword others allows to map all the remaining stuff that hasn't already mapped.

Example to assign array :

type array_type is array(0 to 5) of std_logic_vector(7 downto 0);
constant my_array : array_type := (0 => x"AB", 1 => x"CD", others => (others => '0'));
like image 38
Rafael Catrou Avatar answered Sep 30 '22 01:09

Rafael Catrou