-
Notifications
You must be signed in to change notification settings - Fork 0
/
ULASomaSub.vhd
25 lines (23 loc) · 1006 Bytes
/
ULASomaSub.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all; -- Biblioteca IEEE para funções aritméticas
entity ULASomaSub is
generic ( larguraDados : natural := 8 );
port (
entradaA, entradaB: in STD_LOGIC_VECTOR((larguraDados-1) downto 0);
seletor: in STD_LOGIC_VECTOR(1 downto 0);
saida: out STD_LOGIC_VECTOR((larguraDados-1) downto 0)
);
end entity;
architecture comportamento of ULASomaSub is
signal soma : STD_LOGIC_VECTOR((larguraDados-1) downto 0);
signal subtracao : STD_LOGIC_VECTOR((larguraDados-1) downto 0);
signal passa: STD_LOGIC_VECTOR((larguraDados-1) downto 0);
begin
soma <= STD_LOGIC_VECTOR(unsigned(entradaA) + unsigned(entradaB));
subtracao <= STD_LOGIC_VECTOR(unsigned(entradaA) - unsigned(entradaB));
passa <= STD_LOGIC_VECTOR(unsigned(entradaB));
saida <= soma when (seletor = "01") else
subtracao when(seletor = "00") else
passa when (seletor = "10");
end architecture;