Advertisement
Guest User

Untitled

a guest
Nov 24th, 2011
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.21 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.std_logic_1164.all;
  3.  
  4. entity alu1bit is
  5.    port(  i_X    : in std_logic;
  6.           i_Y    : in std_logic;
  7.           i_Less :  in std_logic;
  8.           i_Cin  :  in std_logic;
  9.           i_Op   :  in std_logic_vector(3 downto 0);
  10.           o_Res  :  out std_logic;
  11.           o_Cout :  out std_logic;
  12.           o_Set  :  out std_logic);
  13.  end alu1bit;
  14.  
  15.  architecture structure of alu1bit is
  16.    
  17.    
  18.    component add_sub_wc is
  19.      port(      A : in std_logic;
  20.                 B : in std_logic;
  21.          carry_in : in std_logic;
  22.          nAdd_Sub : in std_logic;
  23.             total : out std_logic;
  24.         carry_out : out std_logic);
  25.     end component;
  26.    
  27.   signal XYAnd, XYOr, XYXor, XYNand, XYNor, XYAdd, XYSub, XYSet, carry_add, carry_sub, YNot, XNot : std_logic;
  28.    
  29.  begin
  30.   --Xmux and with Ymux
  31.   XYAnd <= i_X AND i_Y;
  32.  
  33.   --Xmux or with Ymux
  34.   XYOr  <= i_X OR i_Y;
  35.  
  36.   --X Xor with Y
  37.   XYXor <= i_X XOR i_Y;
  38.  
  39.   --X NAND with Y
  40.   XYNand <= i_X NAND i_Y;
  41.    
  42.   --X NOR with Y
  43.   XYNor <= i_X NOR i_Y;
  44.  
  45.   --Y Inverted
  46.   YNot <= NOT i_Y;
  47.  
  48.   --X Inverted
  49.   XNot <= NOT i_X;
  50.  
  51.   --Add X with Y
  52.   addXY : add_sub_wc
  53.   port map(  A          => i_X,
  54.              B          => i_Y,
  55.              carry_in   => i_Cin,
  56.              nAdd_Sub    => '0',
  57.              total      => XYAdd,
  58.              carry_out  => carry_add);
  59.              
  60.   --Subtract X with Y          
  61.   subXY : add_sub_wc
  62.   port map(  A          => i_X,
  63.              B          => YNot,
  64.              carry_in   => i_Cin,
  65.              nAdd_Sub   => '0',
  66.              total      => XYsub,
  67.              carry_out  => carry_sub);
  68.  
  69.              
  70.   --Select carryout value based on operation
  71.   with i_OP select
  72.   o_Cout <= carry_sub when  "0011",
  73.             carry_sub when  "0111",
  74.             carry_add when others;
  75.  
  76.    
  77.  
  78.  
  79.   --Selecting which value we want to send to output      
  80.   with i_OP select
  81.   o_Res <= XYAnd  when "0000", --AND
  82.            XYOr   when "0001", --OR
  83.            XYAdd  when "0010", --ADD
  84.            XYSub  when "0011", --SUBTRACT
  85.            XYNor  when "0100", --NOR
  86.            XYXor  when "0101", --XOR
  87.            XYNand when "0110", --NAND
  88.            i_Less when "0111", --SET LESS THAN
  89.            '0' when others;    
  90.  
  91.  
  92.  end structure;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement