Conditional Statement
조건문
\(\texttt{if}\) Statement
※ if문과 case문은 PROCESS문 안에서 Sequential하게 수행 되어야 한다.
- if문과 case문 내부에는 여러 문장이 위치하기 때문에,
Concurrent하게 진행될 수 없다.
Example. General \(\texttt{if}\) Statement
IF (sel = '1') THEN
y <= a;
ELSE
y <= b;
END IF;
Example. Multiple \(\texttt{if}\) Statement
IF (sel0 = '1') THEN
y <= a;
ELSIF (sel1 = '1') THEN
y <= b;
ELSE
y <= c;
END IF;
Example. \(\texttt{if}\) Statement without \(\texttt{else}\)
IF (sel0 = '1') THEN
y <= a;
END IF;
- \(\texttt{else}\)를 생략시킬 경우, VHDL은 원래 변수값을 유지시키도록 아래와 같이 \(\texttt{else}\)문을 자동으로 추가하여 Synthesis한다.
IF (sel0 = '1') THEN
y <= a;
ELSE -- automatically generated
y <= y; -- automatically generated
END IF;
Example. \(\texttt{if}\) statement
IF (x < 10) THEN
a := b;
END IF;
IF (day = sunday) THEN
weekend := true; -- true -> defined in library
ELSIF (day = saturday) THEN
weekend := true;
ELSE
weekday := true;
END IF;
\(\texttt{case}\) Statement
※ if문과 case문은 PROCESS문 안에서 Sequential하게 수행 되어야 한다.
CASE (expression) IS
WHEN selected_value_1 => assignment_statement_1;
WHEN selected_value_2 => assignment_statement_2;
...
WHEN selected_value_n-1 => assignment_statement_n-1;
WHEN OTHERS => assignment_statement_n;
END CASE;
Example. \(\texttt{case}\) Statement
CASE (sel) IS
WHEN "00" | "01" => y <= d(0);
WHEN "02" => y <= d(2);
WHEN OTHERS => y <= d(3);
END CASE;
- \(\texttt{sel}\)값이 \(\texttt{when}\)의 값에 일치하면, 그 후속 문장을 수행한다.
- \(\texttt{when}\)절의 가장 마지막에는 \(\texttt{othres}\)절이 위치해서 Otherwise Case를 꼭 처리해야 한다.
Example. \(\texttt{case}\) Statement
TYPE bit_vec_type IS array(0 to 1) OF bit;
VARIABLE bit_vec_val : bit_vece_type;
VARIABLE int_val : integer;
...
CASE bit_vec_val IS
WHEN "00" => int_val := 0;
WHEN "01" => int_val := 1;
WHEN "10" => int_val := 2;
WHEN "11" => int_val := 3;
END CASE;
\(\texttt{when-else}\) Statement (조건적 병렬 처리문, Data Flow)
※ when-else문과 with-select-when문은 Concurrent하게 처리되어야 한다.
- when-else문과 with_select_when문 내에는 한 문장으로 구성되기 때문에
Concurrent하게 진행되어도 오류가 발생되지 않는다.
signal_name <= input_1 WHEN (condition_1) ELSE
input_2 WHEN (condition_2) ELSE
...
input_n-1 WHEN (condition_n-1) ELSE
input_n;
\(\texttt{with-select-when}\) Statement (선택적 병렬 처리문, Data Flow)
※ when-else문과 with-select-when문은 Concurrent하게 처리되어야 한다.
WITH (expression) SELECT
signal_name <= input_1 WHEN selected-value_1,
input_2 WHEN selected-value_2,
...
input_n-1 WHEN selected-value_n-1,
input_n WHEN OTHERS;