﻿<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="thpdoc.xsl"?>
<page id="select" suffix=" Statement">
  <subsection>Describes a multiplexer. Similar to the <kw>switch</kw> statement. Can be used inside an implicit/explicit process or a function.<code>SignalOrVar = select(Expression)
{
	case Val1:
	case Val2:
		AssignedExpr1;
	case Val3:
		AssignedExpr2;
		break;
	case ValN:
		...
		break;
	default:
		AssignedExprN;
		break;
}</code>
	<p>The <kw>select</kw> statement can be specified inside a process or function. It uses C++ syntax and will be directly converted to a VHDL case statement.</p>
</subsection>
<section name="Remarks">
	<p>The <kw>select</kw> statement is a shorter form of a <kw>switch</kw> statement where every case expression assigns the same variable or signal.</p>
	<p>If the expression used in the <kw>select</kw> statement is of an enumeration type and you want to ensure that all cases have been considered, use the <kw>selectall</kw> statement.</p>
</section>
<examples>
	<example name="State coder">
<code>entity SomeFSM
{
	enum State
	{
		Initial,
		Reading,
		Writing,
	}
	
    signal State CurrentState = State.Initial;
    signal logic[8] StateCode;
    
    StateCode = select(CurrentState)
    {
    	case State.Initial:
    	case State.Reading: 1;
    	case State.Writing: 2;
    };
}</code>
	Generated VHDL code:
<code>entity Some_FSM is
end entity Some_FSM;

architecture Behavioral of Some_FSM is
	signal Current_State : Some_FSM_State := Initial;
	signal State_Code : std_logic_vector(7 downto 0);
	
	begin
		State_Code &lt;= X"01" when ((Current_State = Initial)) or ((Current_State = Reading))
			else X"02" when ((Current_State = Writing));
		
end architecture Behavioral;</code>
	</example>
</examples>
  <seealso id="process"/>
  <seealso id="functions"/>
  <seealso id="selectall"/>
  <seealso id="switch"/>
  <seealso id="switchall"/>
</page>