Advertisement
nontawat1996

Assignment-VHDL

Feb 27th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.53 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date:    23:26:17 02/27/2016
  6. -- Design Name:
  7. -- Module Name:    addAndSub - Behavioral
  8. -- Project Name:
  9. -- Target Devices:
  10. -- Tool versions:
  11. -- Description:
  12. --
  13. -- Dependencies:
  14. --
  15. -- Revision:
  16. -- Revision 0.01 - File Created
  17. -- Additional Comments:
  18. --
  19. ----------------------------------------------------------------------------------
  20. library IEEE;
  21. use IEEE.STD_LOGIC_1164.ALL;
  22. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  23. use IEEE.std_logic_arith.ALL;
  24. -- Uncomment the following library declaration if using
  25. -- arithmetic functions with Signed or Unsigned values
  26. --use IEEE.NUMERIC_STD.ALL;
  27.  
  28. -- Uncomment the following library declaration if instantiating
  29. -- any Xilinx primitives in this code.
  30. --library UNISIM;
  31. --use UNISIM.VComponents.all;
  32.  
  33. entity addAndSub is
  34.     Port ( A,B : in  STD_LOGIC_VECTOR (3 downto 0);
  35.            SingA : in  STD_LOGIC;
  36.            SingB : in  STD_LOGIC;
  37.               Operator : in STD_LOGIC;
  38.            C : out  STD_LOGIC_VECTOR (4 downto 0));
  39. end addAndSub;
  40.  
  41. architecture Behavioral of addAndSub is
  42.     signal x : integer := 0;
  43. begin
  44.  
  45.     process
  46.         variable AInt, BInt, AB : integer;
  47.     begin
  48.         AInt := conv_integer(A(2 downto 0));
  49.         BInt := conv_integer(B(2 downto 0));
  50.        
  51.         if A(3) = '1' then AInt := AInt*(-1);
  52.         end if;
  53.        
  54.         if B(3) = '1' then BInt := BInt*(-1);
  55.         end if;
  56.        
  57.         AB := AInt + BInt;
  58.         C <= conv_std_logic_vector(AB, 4);
  59.     end process;
  60. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement