Masking (Constant)

Posted 2008. 10. 8. 22:27 by MINOK

1. 문제

- 위의 VHDL 설계에서 sel의 값에 의해서 하위 2비트, 혹은 상위 2비트가 출력으로 전송되었다. 이 때 mask된 비트는 '0'으로 고정되어 있다. mask된 비트가 '1'로 고정되는 회로를 설계하여라.

 

2. 문제 분석

- constant : 초기에 선언한 상수의 값을 유지하는데 사용하며, VHDL문장 작성에 있어 수정이나 확장에 도움을 준다. 대입기호 :=를 사용하며 초기값이 즉시 대입되고 한번 대입된값을 바꿀수 없다.

 

3. VHDL code

library ieee;

use ieee.std_logic_1164.all;

 

entity exam5 is

port (k1: in std_logic_vector(3 downto 0);

sel: in std_logic;

y_out: out std_logic_vector(3 downto 0) );

end exam5;

 

architecture exam of exam5 is

constant mark1 : std_logic_vector := "0011";

constant mark2 : std_logic_vector := "1100";

begin

process(sel,k1)

begin

if(sel='1') then

y_out <= not(k1 xor mark1) or k1 ;

else

y_out <= k1 and mark2;

end if;

end process;

end exam;

 

 

4. Simulation