Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple ALU

Status
Not open for further replies.

user4637

Technical User
Joined
Dec 6, 2009
Messages
5
Location
CA
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.STD_logic_signed.all;

entity ALU is
port(
A : in STD_LOGIC_VECTOR(7 downto 0);
B : in STD_LOGIC_VECTOR(7 downto 0);
funcSel : in STD_LOGIC_VECTOR(3 downto 0);
negative : out STD_LOGIC;
zero : out STD_LOGIC;
G : out STD_LOGIC_VECTOR(7 downto 0)
);
end ALU;


architecture Behavioural of ALU is

signal G_int: STD_LOGIC_VECTOR(7 downto 0);

constant ONE: STD_LOGIC_VECTOR(7 downto 0) := "00000001";

begin
G <= G_int; -- G est combinatoires et depend de la variable interne G_int
--
-- Les valeurs de zero et negatif sont calcules ici.
-- NOTE: If faut utilise un processus pour le calcu de zero et negatif
-- pour s'assurer qu'un changement arrive seulement apres
-- un changement sur l'operateur (funcSel). De cette facon,
-- funcSel part Gint et celui-ci part le processus de changement pour N et Z.
--
out_NZ: process(G_Int)
begin
if G_int="0000" then
zero <= '1';
else
zero <= '0';
end if;
if G_int(7)='1' then
negative <= '1';
else
negative <= '0';
end if;
end process;
--
-- Calcul de G_int
-- NOTE: Comme indique ci-haut, funcSel part le processus de G_int.
-- De cette facon, les registres A et B sont charges avec leurs valeurs respective
-- et apres l'operation est executee. Cette facon d'ecrire garde la derniere
-- valeur d'operation du ALU pour qu'on puisse verifier les operations Z et N.
-- Ces valeurs sont necessaire dans les commandes BRAN et BRAZ.
--
out_G_int: process(funcSel,A,B)
begin
case funcSel is
--
-- Completer le code suivant pour implanter les functions du ALU
--
when "0000" => G_int<=A;
when "0001" => G_int<=B;
when "0010" => G_int<=(A+1);
when "0011" => G_int<=(B+1);
when "0100" => G_int<=(A-1);
when "0101" => G_int<=(B-1);
when "0110" => G_int<=A+B;
when "0111" => G_int<=A-B;
when "1000" => G_int<=A and B;
when "1001" => G_int<=A or B;
when "1010" => G_int<=A xor B;
when "1011" => G_int<=not B;
when "1100" => G_int<=(0-B);
when "1101" => G_int<=(B(7) & B(7 downto 1));
when "1110" => G_int<=('0' & B(7 downto 1));
when "1111" => G_int<=(B(6 downto 0) & '0');
-- A --> funcSel = 0000
when others => G_int<=A;
end case;
end process;
end Behavioural;
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top