0% found this document useful (0 votes)
69 views18 pages

Previamente Se Realiza El Codigo VHDL para Un Sumador Completo

The document discusses VHDL code for full adders and 4-bit and 16-bit adders. It begins with code for a basic full adder component. It then shows how to generate a 4-bit adder using four instances of the full adder. Next, it presents code for a 16-bit adder that includes carry and overflow outputs. Finally, it modifies the 16-bit adder to use a signed data type.

Uploaded by

phoenyxoscuro
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views18 pages

Previamente Se Realiza El Codigo VHDL para Un Sumador Completo

The document discusses VHDL code for full adders and 4-bit and 16-bit adders. It begins with code for a basic full adder component. It then shows how to generate a 4-bit adder using four instances of the full adder. Next, it presents code for a 16-bit adder that includes carry and overflow outputs. Finally, it modifies the 16-bit adder to use a signed data type.

Uploaded by

phoenyxoscuro
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18

PREGUNTA A

PREVIAMENTE SE REALIZA EL CODIGO VHDL PARA UN SUMADOR COMPLETO

LIBRARY ieee ;

USE ieee.std_logic_1164.all ;

ENTITY SUMADORCOMPLETO IS

PORT ( Cin, x, y : IN STD_LOGIC ;

s, Cout : OUT STD_LOGIC ) ;

END SUMADORCOMPLETO ;

ARCHITECTURE LogicFunc OF SUMADORCOMPLETO IS

BEGIN

s <= x XOR Y XOR Cin ;

cout <= (x and y ) or ( cin and x) or ( cin and y ) ;

END LogicFunc;
FULL ADDER 4

CÓDIGO VHDL—SE GENERA EL FULL ADDER USANDO EL SUMADOR COMPLETO

LIBRARY IEEE ;

USE IEEE.STD_LOGIC_1164.ALL ;

ENTITY sumador4 IS

PORT ( CIN : IN STD_LOGIC ;

X3, X2, X1, X0 : IN STD_LOGIC ;

Y3, Y2, Y1, Y0 : IN STD_LOGIC ;

S3, S2, S1, S0 : OUT STD_LOGIC ;

COUT : OUT STD_LOGIC );

END sumador4 ;

ARCHITECTURE STRUCTURE OF ADDER4 IS

SIGNAL C1, C2, C3 : STD_LOGIC ;

COMPONENT FULLADD

PORT ( CIN, X, Y : IN STD_LOGIC ;

S, COUT : OUT STD_LOGIC );

END COMPONENT ;

BEGIN

STAGE0 : FULLADD PORT MAP (CIN, X0, Y0, S0, C1 );

STAGE1 : FULLADD PORT MAP (C1, X1, Y1, S1, C2 );

STAGE2 : FULLADD PORT MAP (C2, X2, Y2, S2, C3 );

STAGE3 : FULLADD PORT MAP ( CIN => C3, COUT => COUT, X =>
X3,

Y => Y3, S => S3) ;


END STRUCTURE ;

PREGUNTA B

PRIMERO DECLARAMOS EL PAQUETE DE FULLADD EN COMPONENT

LIBRARY ieee ;

USE ieee.std_logic_1164.all ;
PACKAGE BLOQUESUMADORCOMPLETO IS

COMPONENT SUMADORCOMPLETO

PORT ( Cin, x, y : IN STD_LOGIC ;

s, Cout : OUT STD_LOGIC ) ;

END COMPONENT ;

END BLOQUESUMADORCOMPLETO ;

--DECLARACIÓN DE PAQUETE DE SUMADORCOMPLETO

SUMADOR DE 4 BITS (USANDO PAQUETE DE SUMADORCOMPLETO)

LIBRARY ieee ;

USE IEEE.STD_LOGIC_1164.ALL ;

USE work.BLOQUESUMADORCOMPLETO.all ;

ENTITY sumador41 IS

PORT ( Cin : IN STD_LOGIC ;

x3, x2, x1, x0 : IN STD_LOGIC ;

y3, y2, y1, y0 : IN STD_LOGIC ;


s3, s2, s1, s0 : OUT STD_LOGIC ;

Cout : OUT STD_LOGIC ) ;

END sumador41 ;

ARCHITECTURE Structure OF sumador41 IS

SIGNAL c1, c2, c3 : STD_LOGIC ;

BEGIN

STAGE0: SUMADORCOMPLETO PORT MAP (CIN, X0, Y0, S0, C1 );

STAGE1: SUMADORCOMPLETO PORT MAP (C1, X1, Y1, S1, C2 );

STAGE2: SUMADORCOMPLETO PORT MAP (C2, X2, Y2, S2, C3 );

STAGE3: SUMADORCOMPLETO PORT MAP ( CIN => C3, COUT => COUT,

X => X3,Y => Y3, S =>


S3) ;

END Structure ;

--FULL ADDER SUMADOR DE 4 BITS


PREGUNTA C

SUMADOR DE 16 BITS CON SEÑALES DE ACARREO Y DESBORDAMIENTO

LIBRARY ieee ;

USE ieee.std_logic_1164.all ;

USE ieee.std_logic_signed.all ;

ENTITY sumador16 IS

PORT ( Cin : IN STD_LOGIC ;

X,Y :IN STD_LOGIC_VECTOR(15 DOWNTO 0) ;

S :OUT STD_LOGIC_VECTOR(15 DOWNTO 0) ;

Cout, Overflow : OUT STD_LOGIC ) ;

END sumador16 ;

ARCHITECTURE Behavior OF sumador16 IS

SIGNAL Sum : STD_LOGIC_VECTOR(16 DOWNTO 0) ;

BEGIN

Sum <= ('0' & X)+Y+Cin ;


S <= Sum(15 DOWNTO 0) ;

COUT <= Sum(16) ;

OVERFLOW <= Sum(16)XOR X(15) XOR Y(15) XOR SUM(15);

END BEHAVIOR;
PREGUNTA D

library ieee ;

USE ieee.std_logic_1164.all ;

USE ieee.std_logic_arith.all ;

ENTITY sumador161 IS

PORT ( Cin : IN STD_LOGIC ;

X, Y : IN SIGNED(15 DOWNTO 0) ;

S : OUT SIGNED(15 DOWNTO 0) ;

Cout, Overflow : OUT STD_LOGIC ) ;

END sumador161 ;

ARCHITECTURE Behavior OF sumador161 IS

SIGNAL Sum : SIGNED(16 DOWNTO 0) ;

BEGIN

Sum <= ('0' & X)+Y+Cin ;

S <= Sum(15 DOWNTO 0) ;

COUT <= Sum(16) ;

OVERFLOW <= Sum(16)XOR X(15) XOR Y(15) XOR SUM(15);

END BEHAVIOR;

-- USO DE PAQUETE ARITMÉTICO PARA UN SUMADOR16 BITS


Ejemplo 5.11 Problema: Escriba el código de VHDL para especificar el circuito
de la figura 5.43.
LIBRARY ieee;
USE ieee.std_logic_1164.all ;
USE work.fulladd_package.all ;
ENTITY comparator IS
PORT ( X, Y : IN STD_LOGIC_VECTOR(3 DOWNTO 0) ;
V, N, Z : OUT STD_LOGIC ) ;
END comparator ;
ARCHITECTURE Structure OF comparator IS
SIGNAL S : STD_LOGIC_VECTOR(3 DOWNTO 0) ;
SIGNAL C : STD_LOGIC_VECTOR(1 TO 4) ;
BEGIN
stage0: fulladd PORT MAP ( '1', X(0), NOT Y(0), S(0), C(1) ) ;
stage1: fulladd PORT MAP ( C(1), X(1), NOT Y(1), S(1), C(2) ) ;
stage2: fulladd PORT MAP ( C(2), X(2), NOT Y(2), S(2), C(3) ) ;
stage3: fulladd PORT MAP ( C(3), X(3), NOT Y(3), S(3), C(4) ) ;
V <= C(4) XOR C(3) ;
N <= S(3) ;
Z <= '1' WHEN S(3 DOWNTO 0) "0000" ELSE '0';

END Structure;
--Código estructural de VHDL para el circuito comparador
*5.17 Considere el código de VHDL de la figura P5.2. Dada la relación entre las
señales IN y OUT, ¿cuál es la funcionalidad del circuito descrito por el código?
Comente si este código constituye o no un buen estilo para la funcionalidad que
representa.

LIBRARY ieee ;
USE ieee.std_logic_1164.all ;
ENTITY problem517 IS
PORT ( Input : IN STD_LOGIC_VECTOR(3 DOWNTO 0) ;
Output : OUT STD_LOGIC_VECTOR(3 DOWNTO 0) ) ;
END problem517 ;
ARCHITECTURE LogicFunc OF problem517 IS
BEGIN
WITH Input SELECT
Output <= "0001" when "0101" ,
"0010" when "0110" ,
"0011" when "0111" ,
"0100" when "1001" ,
"0110" when "1010" ,
"0011" when "1101" ,
"0110" when "1110" ,
"1001" when "1111" ,
"0000" when others ;
end LogicFunc;
El código representa un multiplicador. Multiplica los dos bits inferiores de entrada por los dos
bits superiores de entrada, produciendo la salida de cuatro bits. el estilo del código es
deficiente, porque no es evidente lo que se describe.

5.19 Derive un esquema para realizar la resta usando operandos BCD. Muestre un diagrama
de bloques para el circuito restador.
Sugerencia: la resta puede realizarse fácilmente si los operandos están en representación de
complemento a 10 ( complemento a la base). En esta representación, el dígito signo es 0 para
un número positivo y 9 para un número negativo.
La resta BCD se puede realizar utilizando la representación del complemento de 10, utilizando
un enfoque que es similar a los complementos de 2; son los complementos de radix en
sistemas numéricos donde los radices son 10 y 2, respectivamente.
Consideramos a x e y BCD los números dados en la representación del complemento de 10, de
modo que el signo (el extremo izquierdo) BCD dígito sea 0 para números positivos y 9 para
números negativos.
Luego, la operación de resta s = x - y se realiza al encontrar el complemento de y de los 10 y
sumando a x, ignorando cualquier resultado de la posición de signo-dígito.

POR EJEMPLO
X=068
Y=043
EL COMPLEMENTO A BASE 10 DE Y ES: 957
ASÍ: S´= 068 + 957 = 1025
Luego no se considera el arrastre de la posición de signo, así nuestro resultado será:
S=025

*6.18 Considere el código de VHDL de la fi gura P6.2. ¿Qué tipo de circuito representa?
Comente si el estilo de código usado es una buena elección para el circuito que representa.
El código es un decodificador dos a cuatro con una entrada enable. No es un buen estilo para
definir este decodificador. El código no es fácil de leer. Es mejor utilizar el estilo de las figuras
6.30 o 6.46.

6.26 Cree una entidad de VHDL llamada if2to4 que represente un decodificador binario que
use una instrucción if-then-else. Cree una segunda entidad llamada h3to8 que represente el
decodificador binario tres a ocho de la fi gura 6.17, con dos instancias de la entidad if2to4.
--CREAMOS UN CÓDIGO IF2OF4

library ieee ;
use ieee.std_logic_1164.all;

entity if2to4 is
port ( w : IN std_logic_vector ( 1 downto 0 );
En : IN std_logic;
y : OUT std_logic_vector ( 3 downto 0 ));
END if2to4;

ARCHITECTURE Behavior OF if2to4 IS


BEGIN
PROCESS (En , w)
BEGIN
IF En = '0' then
y <= "0000";
ELSE
IF w = "00" then
y <= "0001";
ELSIF w = "01" then
y <= "0010";
ELSIF w = "10" then
y <= "0100";
ELSE
y <= "1000";
end if;
end if;
end process;
end Behavior;
LIBRARY IEEE;
USE ieee.std_logic_1164.all;
PACKAGE IF2TO4_PACKAGE IS
COMPONENT IF2TO4
PORT ( W : IN STD_LOGIC_VECTOR( 1 DOWNTO 0);
En: IN STD_LOGIC;
y : OUT STD_LOGIC_VECTOR( 3 DOWNTO 0));
END COMPONENT;
END IF2TO4_PACKAGE ;
library ieee;
use ieee.std_logic_1164.all;
use work.if2to4_package.all;

ENTITY h3to8 is
port ( w: in std_logic_vector(2 downto 0);
En: in std_logic;
y: out std_logic_vector(7 downto 0);
END h3to8;
ARCHITECTURE structure of h3to8 is
signal enableTop, enableBot: std_logic;
BEGIN
enableTop <= w(2) and En;
enableBOT <= (NOT w(2)) and En;

decoder1: if2to4 PORT MAP ( w (1 DOWNTO 0 ), EnableBot, y( 3 downto 0 ));


decoder2: if2to4 PORT MAP ( w (1 DOWNTO 0 ), EnableTop, y( 7 downto 4 ));
end structure;

You might also like