12 Kasım 2009 Perşembe

VHDL-Aritmetik Lojik Ünitesi (ALU) Tasarımı

Soru-3 : Aritmetik Lojik Ünitesi (ALU) Tasarımı
32-bitlik ALU birimi 6 farklı işlem yapabilmektedir. ALU nun blok gösterimi verilmiştir. ALU' nun 32 bitlik iki giriş sinyalleri ile 3 bit kontrol için kullanılan girişi vardır. 32 bitlik çıkış ile birlikte iki durum (Zero, Carry) bayrağı vardır. ALU da yapılan işlemler tablo verilmektedir. Buna göre, ALU nun VHDL gerçeklemesini yapınız.




















library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_arith.all;

use ieee.std_logic_unsigned.all;


entity ALU is

port
(
a: in std_logic_vector (31 downto 0);

b: in std_logic_vector (31 downto 0);
s: in std_logic
_vector (2 downto 0);
res: out std_logic_vector (31 downto 0);
z: out std_logic;
c: out std_logic
);
end ALU;


architecture behaviour of ALU is

signal
result : std_logic_vector(31 downto 0);

signal temp: std_logic_vector(32 downto 0);

begin

process(s)

begin


if s = "000" then
result <= a and b;

c<='0';

if result = (a xor a) then

z<='1';

else

z<='0';

end if;


elsif s="001" then

result <= a or b;

if result = (a xor a) then

z<='1';

else

z<='0';
end if;

c<='0';


elsif s="010" then

temp<=a + b;

if temp = (a xor a) then

z<='1';

else

z<='0';

end if;

if temp(32)='1' then

c<='1';

elsif temp(32)='0' then
c<='0';

end if;

result<=temp(31 downto 0);


elsif s="011" then

result<=a;

c<='0';
if result=(a xor a) then
z<='1';

else

z<='0';

end if;

elsif s="110" then

if a > b or a = b then

result<=a-b;
c<='0';

if a=b then

z<='1';

else

z<='0';

end if;

elsif a <b then
z<='0';

c<='1';
res<=(a+(not b)+1);

end if;


elsif s="111" then

result<=b;
if res = (b xor b) then
z<='1';
else
z<='0';
end if;
c<='0';
end if;

res <= result;

end process;

end behaviour;

Hiç yorum yok:

Yorum Gönder