Read in EN

conditional assignment

scode의 conditional assignment 형식은 다음과 같다.

destination <= (value1, condition1,value2, condition2, value3, ...)

Condition1인 경우 value1, condition2인 경우 value2, condition3인 경우 value3가 할당된다. 다만 combinational인 경우는 register가 없으므로 value가 항상 1개씩 많아야 한다.

scode는 VHDL/Verilog과 달리 이러한 conditional assignment를 combinational, sequential statement에 모두 사용할 수 있다. 물론 sequential statement에서는 if 문장도 사용할 수 있지만 가급적 scode의 위의 형식대로 사용하는 것을 권장한다.

이는 회로의 기술이 combinational로 구현했다 다시 sequential로 변경해야 하거나 반대의 경우 유용하다.

Scode의 conditional assignment는 sequential statement에서 사용되는 경우 recursive를 지원한다. 즉 value가 들어가는 위치에 다시 conditional assigment 형식이 들어갈 수 있다. 이러한 recursive 지원은 nested if를 구현하는 데 있어 유용하다.

destination <= (value1, condition1,(value2, condition2, value3, ...))

아래는 combinatial statement의 예이다.

b <= (1, a, 0)
c <= (d, -a, e)

(Converted code) 

b <= '1' when a = '1' else '0';
c <= d when a = '0' else e;

다음은 sequential statement의 예이다.

with sequence(clk,srst=reset) :
    f <= (a, -b)
    g <= (1, a, (b,c,d))

(Converted code) 

process(clk)
begin
    if rising_edge(clk) then 
        if reset = '1' then 
            f <= '0';
            g <= '0';
        else 
            if b = '0' then
                f <= a;
            end if;
            if a = '1' then
                g <= '1';
            else
                if c = '1' then
                    g <= b;
                else
                    g <= d;
                end if;
            end if;
        end if;
    end if;
end process;

Sequential statement에서 if보다는 scode의 conditional assignment로 표현하는 것이 훨씬 간략함을 알 수 있다.

← All posts