Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 6

-- primera parte del programa, solo esta comparando los valores que ingresamos--

library IEEE;
use IEEE.STD_LOGIC_1164.all;

entity ALU is
PORT
(
clk : in std_logic;
a_in : in std_logic_vector(3 downto 0);
b_in : in std_logic_vector(3 downto 0);
selec : in std_logic_vector(3 downto 0);
Cn, m : in std_logic;
compara : out std_logic);

end ALU;

architecture ALU of ALU is


signal L,N,O,P, J : std_logic_vector(3 downto 0) ;
begin
proceso1 : process (clk,L,N,O,P,J)
begin
if (clk'event and clk ='1') then
L <= a_in;
O <= L;
N <= b_in;
P <= N;

else
J <= "0000";
end if;
end process;

compara <= '1' when L = N else '0' ;

end ALU;

-- segunda prueba agregando el selector y la condicion de logica y arimetica --

library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity ALU is
PORT
(
clk : in std_logic;
a_in : in std_logic_vector(3 downto 0);
b_in : in std_logic_vector(3 downto 0);
a_out : out std_logic_vector(3 downto 0);
selec : in std_logic_vector(3 downto 0);
Cn, m : in std_logic;
compara : out std_logic);
end ALU;

architecture ALU of ALU is


signal L,N,O,P, J : std_logic_vector(3 downto 0) ;
signal log_o_ari : std_logic;

begin
proceso1 : process (clk,L,N,O,P,J)
begin
if (clk'event and clk ='1') then
L <= a_in;
O <= L;
N <= b_in;
P <= N;

if (m = '0' and Cn= '0') then


log_o_ari <= '0' ;
else
log_o_ari <= '1' ;
end if;

else
J <= "0000";
end if;
end process;

proceso2 : process (log_o_ari,selec,L,N,Cn,m,J)


begin

if log_o_ari = '0' then

if selec = "0000" then


a_out <= L ;
elsif
selec = "0001" then
a_out <= (L + N);
elsif
selec = "0010" then
a_out <= (L - N);
elsif
selec = "0011" then
a_out <= ( "0000" - "0001" ) ; -- implementar el
( -1 (complemento a 2) )--
elsif
selec = "0100" then
a_out <= (L * N) ;
else
J <= "0000";
end if ;
else
J <= "0001";

end if;

end process ;

end ALU;
---- V2 DEL PROGRAMA ----

library IEEE;
use IEEE.STD_LOGIC_1164.all;
USE ieee.std_logic_unsigned.all;
entity ALUV2 is
PORT
(
clk : in std_logic;
a_in : in std_logic_vector(3 downto 0);
b_in : in std_logic_vector(3 downto 0);
selec : in std_logic_vector(3 downto 0);
Cn, m : in std_logic;
Cn_4 : out std_logic;
compara : out std_logic;
a_out : out std_logic_vector(3 downto 0));

end ALUV2;

architecture ALUV2 of ALUV2 is

signal L,N,O,P, J : std_logic_vector(3 downto 0);


signal log_o_ari : std_logic;
signal y_temp : std_logic_vector(4 downto 0) ;

begin
proceso1 : process (clk,L,N,O,P,J)
begin
if (clk'event and clk ='1') then
L <= a_in;
N <= b_in;

if (m = '0' and Cn= '0') then


log_o_ari <= '0' ;
else
log_o_ari <= '1' ;
end if;
else
J <= "0000";
end if;
end process;

proceso2 : process (log_o_ari,selec,L,N)


begin

if log_o_ari = '0' then


if selec = "0001" then

y_temp <= ('0' & L )+ N;


else
y_temp <= ('0' & L )+ not N ;
end if ;
else
J <= "0001";

end if;

end process ;

proceso3 : process (y_temp)


begin
Cn_4 <= y_temp (4);
a_out <= y_temp (3 downto 0);
end process ;

end ALUV2;

------ CODIGO CON OPERACIONES ARITMETICAS PROBADAS ------

library IEEE;
use IEEE.STD_LOGIC_1164.all;
USE ieee.std_logic_unsigned.all;
entity ALUV2 is
PORT
(
clk : in std_logic;
a_in : in std_logic_vector(3 downto 0);
b_in : in std_logic_vector(3 downto 0);
selec : in std_logic_vector(3 downto 0);
Cn, m : in std_logic;
Cn_4 : out std_logic;
compara : out std_logic;
a_out : out std_logic_vector(3 downto 0));

end ALUV2;

architecture ALUV2 of ALUV2 is

signal L,N,O,P, J : std_logic_vector(3 downto 0);


signal log_o_ari : std_logic;
signal y_temp : std_logic_vector(11 downto 0) ;

begin
proceso1 : process (clk,L,N,O,P,J)
begin
if (clk'event and clk ='1') then
L <= a_in;
N <= b_in;

if (m = '0' and Cn= '0') then


log_o_ari <= '0' ;
else
log_o_ari <= '1' ;
end if;
else
J <= "0000";
end if;
end process;

proceso2 : process (log_o_ari,selec,L,N)


begin

if log_o_ari = '0' then


--OPERACIONES ARITMETICAS
if selec = "0000" then
y_temp <= ("00000000" & L );
elsif selec = "0001" then
y_temp <= ("00000000" & L )+ N ;
elsif selec = "0010" then
y_temp <= ("00000000" & L )+ not N ;
elsif selec = "0011" then -- CAMBIO EN
TABLA: f = A + 1
y_temp <= ("00000000" & L )+ '1' ;
elsif selec = "0100" then
y_temp <= L * ( L * not N) ;
elsif selec = "0101" then
y_temp <= (("0000" & L )+ N ) * ( L + not N) ;
elsif selec = "0110" then
y_temp <= ("00000000" & L )- N - '1' ;
elsif selec = "0111" then
y_temp <= (("0000" & L )* NOT N ) - '1' ;
elsif selec = "1000" then
y_temp <= ("0000" & L )* (L - N) ;
elsif selec = "1001" then
y_temp <= (("0000" & L )* N ) ;
elsif selec = "1010" then --REVISAR
y_temp <= L * N * (L + (NOT N) ) ;
elsif selec = "1011" then
y_temp <= (("0000" & L )* N ) - '1' ;
elsif selec = "1100" then -- CAMBIO EN LA TABLA:
F = A*(A - 2A)
y_temp <= L * (L - ( "0010" * L)) ; --CUIDADO VALORES
NEGATIVOS
elsif selec = "1101" then
y_temp <= ("0000" & L )* (L + N ) ;
elsif selec = "1110" then
y_temp <= ("0000" & L )* (L + NOT N ) ;
elsif selec = "1111" then
y_temp <= ("00000000" & L ) - '1' ;
else
y_temp <= "000000000000" ;
end if ;
--FIN DE OPERACIONES ARITMETICAS
else
J <= "0001";

end if;

end process ;

proceso3 : process (y_temp)


begin
Cn_4 <= y_temp (4);
a_out <= y_temp (3 downto 0);
end process ;

end ALUV2;

You might also like