You are on page 1of 5

Algoritmo para los sumadores

library ieee;

use ieee.std_logic_1164.all;

entity sumador is

port(A,B : in std_logic_vector(3 downto 0);--entradas a sumar

ci : in std_logic;

co : out std_logic;

s: out std_logic_vector(3 downto 0));--suma

end sumador;

architecture sum of sumador is

signal c: std_logic_vector(4 downto 0);--acarreos intermedios

begin

process(A,B,c,ci)

begin c(0)<=ci; --acarreo de entrada

for i in 0 to 3 loop

s(i)<= (A(i) xor B(i)) xor c(i);

c(i+1)<= ((A(i) and B(i)) or (A(i) and c(i))) or (B(i) and c(i));

end loop;

end process;

co<=c(4);

end sum;
Algoritmo para realizer la multiplicacion

library ieee;

use ieee.std_logic_1164.all;

entity multiplicar is

port(A,B : in std_logic_vector(3 downto 0); --numeros de entrada

m : out std_logic_vector(7 downto 0)); --resultado de la multiplicacion

end multiplicar;

architecture mult of multiplicar is

signal f,g,i,h,j,k : std_logic_vector(4 downto 1); --conexiones

signal s,q,r :std_logic_vector(3 downto 0);

signal ci,co,c1,c2,ro : std_logic;

component sumador

port(A,B : in std_logic_vector(3 downto 0);

ci: in std_logic;

co: out std_logic;

s: out std_logic_vector(3 downto 0));

end component;

begin

ci<='0';

ro<= A(0) and B(0); --multiplicacion numero por numero

g(1)<= A(0) and B(1);

g(2)<= A(0) and B(2);

g(3)<= A(0) and B(3);

g(4) <= '0';


f(1) <= A(1) and B (0);

f(2) <= A(1) and B (1);

f(3) <= A(1) and B (2);

f(4) <= A(1) and B (3);

h(1) <= A(2) and B (0);

h(2) <= A(2) and B (1);

h(3) <= A(2) and B (2);

h(4) <= A(2) and B (3);

j(1) <= A(3) and B (0);

j(2) <= A(3) and B (1);

j(3) <= A(3) and B (2);

j(4) <= A(3) and B (3);

--primer sumador

sum1 : sumador port map(f,g,ci,c1,s);

i(1) <= s(1);

i(2) <= s(2);

i(3) <= s(3);

i(4) <= c1;

--segundo sumador

sum2 : sumador port map (h,i,ci,c2,q);

k(1) <= q(1);

k(2) <= q(2);

k(3) <= q(3);


k(4) <= c2;

-- tercer sumador y resultado

sum3 : sumador port map (j,k,ci,co,r);

--resultado de la multiplicacion

m(0) <= ro;

m(1) <= s(0);

m(2) <= q(0);

m(3) <= r(0);

m(4) <= r(1);

m(5) <= r(2);

m(6) <= r(3);

m(7) <= co;

end mult;

You might also like