Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 3.72 KB | None | 0 0
  1. -- ---------------------------------------------------------------------------
  2. --                      8 - Bit General Purpose NVL Computer                  
  3. -- ---------------------------------------------------------------------------
  4. -- Title        : Arithmetical and Logical Unit
  5. --              :
  6. -- Purpose      : This is the ALU of the computer. It performs basic mathmematical
  7. --              : operations, such as addition or multiplication.
  8. --              :
  9. -- Note         : Operation to be performed is selected by Function Select:
  10. --              : FS = 0 --> Addition
  11. --              : FS = 1 --> Bitwise AND
  12. --              : FS = 2 --> Bitwise OR
  13. --              : FS = 3 --> Left logical shift
  14. --              : FS = 4 --> Right logical shift
  15. --              : FS = 5 --> Multiplication
  16. --              :
  17. -- ---------------------------------------------------------------------------
  18. -- Version      : 1.0
  19. -- Date         : 21 October 2016
  20. -- ---------------------------------------------------------------------------
  21.  
  22. library ieee;
  23. use ieee.std_logic_1164.all;
  24. use ieee.numeric_std.all;
  25.  
  26. entity alu is
  27.     port
  28.     (
  29.         cs   : in  std_logic;                     -- Chip select
  30.         fs   : in  std_logic_vector(2 downto 0);  -- Function select
  31.         ms   : in  std_logic;                     -- Multiply select
  32.         opr1 : in  std_logic_vector(7 downto 0);  -- First operand input
  33.         opr2 : in  std_logic_vector(7 downto 0);  -- Second operand input
  34.         y    : out std_logic_vector(7 downto 0);  -- Computation result
  35.         flg  : out std_logic_vector(2 downto 0)   -- Carry and zero flag
  36.     );
  37. end entity;
  38.  
  39. architecture arch of alu is
  40.  signal y_c : std_logic_vector(8 downto 0);   -- Temp output with MSB carry, only add and multiply affects the carry flag.
  41.  --signal y_m : std_logic_vector(15 downto 0);  -- Result of multiplication, whenever result exceeds 8 bits, the carry flag is set.
  42.        
  43.     begin
  44.         process(cs, fs, ms, opr1, opr2, y_c(8))
  45.         variable x : integer range 0 to 7;
  46.         variable y_m : std_logic_vector(15 downto 0);
  47.         -- Result of multiplication, the lower 7 bits is stored in A and upper 7 bits in memory (MPH = 0x3F0).
  48.                                                        
  49.             begin
  50.             if(cs = '1') then
  51.                 case fs is
  52.                     when "000" =>
  53.                         y_c <= std_logic_vector(unsigned('0' & opr1) + unsigned('0' & opr2));                  
  54.                     when "001" =>
  55.                         y_c <= (y_c(8) & opr1) and (y_c(8) & opr2);
  56.                     when "010" =>
  57.                         y_c <= (y_c(8) & opr1) or (y_c(8) & opr2);
  58.                     when "011" =>
  59.                         -- new encoding scheme accepted : XXXX XXXD DDZ0 X100
  60.                         x := to_integer(unsigned(opr2(7 downto 5)));
  61.                         y_c(7 downto x) <= opr1(7 - x downto 0);            -- wont't detect carry
  62.                         y_c(x - 1 downto 0) <= (others => '0');
  63.                     when "100" =>
  64.                         -- new encoding scheme accepted : XXXX XXXD DDZ1 X100
  65.                         x := to_integer(unsigned(opr2(7 downto 5)));
  66.                         y_c(7 - x downto 0) <= opr1(7 downto 0 + x);
  67.                         y_c(7 downto 7 - x) <= (others => '0');
  68.                     when "101" =>                                              
  69.                         if(ms = '0') then
  70.                             y_m := std_logic_vector(unsigned(opr1) * unsigned(opr2));                                              
  71.                             y_c(7 downto 0) <= y_m(7 downto 0);
  72.                             -- output lower 8 bits
  73.                         else
  74.                             y_c(7 downto 0) <= y_m(15 downto 8);
  75.                             -- output higher 8 bits
  76.                         end if;                    
  77.                     when others =>
  78.                     -- ADD otherwise
  79.                     y_c <= std_logic_vector(unsigned('0' & opr1) + unsigned('0' & opr2));                  
  80.                 end case;
  81.             else
  82.                 y_c <= (others => '0');
  83.                 y_m := (others => '0');
  84.                 x   := 0;
  85.             end if;
  86.             end process;
  87.     -- Unregistered computatation output
  88.     y <= y_c(7 downto 0);
  89.     -- Unregistered Carry and Zero output
  90.     flg(0) <= y_c(8);
  91.     flg(1) <= (y_c(7) or y_c(6) or y_c(5) or y_c(4) or y_c(3) or y_c(2) or y_c(1) or y_c(0));      
  92. end architecture;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement