› Foros › Off-Topic › Miscelánea
ENTITY alu IS
PORT (Ci : IN BIT;
A, B, S: IN BIT_vector (3 downto 0);
SUM : OUT BIT_vector (3 downto 0);
CO: buffer BIT);
END alu;
ARCHITECTURE op1 OF alu IS
signal n1,n2: bit_vector (4 downto 0);
signal prov,b2: bit_vector (3 downto 0);
BEGIN
-- operacion A+A+1
n1(0)<=ci;
n2(0)<=ci;
b2<="0001";
F1:for n in a'range generate
prov(n)<= (a(n) xor b(n) xor n1(n));
n1(n+1)<= ((a(n) and b(n)) or ((a(n) or b(n)) and n1(n) ));
SUM(n)<= (prov(n) xor b2(n) xor n2(n));
n2(n+1)<= ((prov(n) and b2(n)) or ((prov(n) or b2(n)) and n2(n) ));
end generate;
co<= n2(4);
end op1;
ARCHITECTURE op2 OF alu IS
signal n1: bit_vector (4 downto 0);
BEGIN
--operacion A-B
n1(0)<='1';
F1:for n in a'range generate
SUM(n)<= (a(n) xor b(n) xor n1(n));
n1(n+1)<= ((a(n) and b(n)) or ((a(n) or b(n)) and n1(n) ));
end generate;
co<= n1(4);
end op2;
-- Entidad de prueba de smador
entity Tsuma is end Tsuma;
architecture A1_Tsuma of Tsuma is
signal Ci, co : BIT;
signal A, B, S, SUM: bit_vector (3 downto 0);
component C_suma is
PORT (Ci : IN BIT;
A, B, S: IN BIT_vector (3 downto 0);
SUM : OUT BIT_vector (3 downto 0);
CO: buffer BIT);
end component;
for C1:C_suma use entity work.alu(op1);
for C2:C_suma use entity work.alu(op2);
begin
process (S)
begin
if S="1100" then
C1: C_suma port map (ci, a, b,s, sum, co);
elsif S="0110" then
C2: C_suma port map (ci, a, b,s, sum, co);
end if;
a<="0001","0010" after 50ns, "0100" after 100 ns, "0101" after 150 ns;
b<="0010";
ci<='0' ;
S<="1100";
end A1_Tsuma;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
---- Uncomment the following library declaration if instantiating
---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity ALU1bit is
Port ( a : in STD_LOGIC;
b : in STD_LOGIC;
CarryIn : in STD_LOGIC;
Less : in STD_LOGIC;
Operacion : in STD_LOGIC_VECTOR (1 downto 0);
BInvert : in STD_LOGIC;
Result : out STD_LOGIC;
CarryOut : out STD_LOGIC);
end ALU1bit;
architecture Behavioral of ALU1bit is
component sumador is
Port ( A : in STD_LOGIC;
B : in STD_LOGIC;
Cin : in STD_LOGIC;
S : out STD_LOGIC;
Cout : out STD_LOGIC);
end component;
signal Resultsum, Op2: STD_LOGIC;
begin
Op2 <= b when BInvert = '0' else not (b);
sum: sumador port map (a,Op2,CarryIn,Resultsum,CarryOut);
Result <= (a and b) when (Operacion = "00") else
(a or b) when (Operacion = "01" ) else
Resultsum when (Operacion = "10") else
Less;
end Behavioral;