Advertisement
nex036ara

rom3

Jan 22nd, 2012
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 4.03 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Logicko projektovanje racunarskih sistema 1
  3. -- 2011/2012
  4. -- Lab 7
  5. --
  6. -- Instruction ROM
  7. --
  8. -- author: Branislav Nikolic, e13592
  9. ----------------------------------------------------------------------------------
  10.  
  11. library IEEE;
  12. use IEEE.STD_LOGIC_1164.ALL;
  13. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  14.  
  15. entity instr_rom is
  16.     Port ( iA : in  STD_LOGIC_VECTOR (4 downto 0);
  17.            oQ : out  STD_LOGIC_VECTOR (14 downto 0));
  18. end instr_rom;
  19.  
  20. architecture Behavioral of instr_rom is
  21.  
  22.     -- ALU instructions --
  23.     constant cMOV : std_logic_vector(5 downto 0) := "000000";
  24.     constant cADD : std_logic_vector(5 downto 0) := "000001";
  25.     constant cSUB : std_logic_vector(5 downto 0) := "000010";
  26.     constant cAND : std_logic_vector(5 downto 0) := "000011";
  27.     constant cOR : std_logic_vector(5 downto 0) := "000100";
  28.     constant cNOT : std_logic_vector(5 downto 0) := "000101";
  29.     constant cINC : std_logic_vector(5 downto 0) := "000110";
  30.     constant cDEC : std_logic_vector(5 downto 0) := "000111";
  31.     constant cSHL : std_logic_vector(5 downto 0) := "001000";
  32.     constant cSHR : std_logic_vector(5 downto 0) := "001001";
  33.     constant cASHL : std_logic_vector(5 downto 0) := "001010";
  34.     constant cASHR : std_logic_vector(5 downto 0) := "001011";
  35.     constant cJMP:  std_logic_vector(5 downto 0) :="010000";
  36.     constant cJMPZ:  std_logic_vector(5 downto 0) :="010001";
  37.     constant cJMPS:  std_logic_vector(5 downto 0) :="010010";
  38.     constant cJMC:  std_logic_vector(5 downto 0) :="010011";
  39.     constant cJMPNZ:  std_logic_vector(5 downto 0) :="010101";
  40.     constant cJMPNS:  std_logic_vector(5 downto 0) :="010110";
  41.     constant cJMNC:  std_logic_vector(5 downto 0) :="010111";
  42.      
  43.     -- Other instructions --
  44.     constant cLD : std_logic_vector(5 downto 0) := "100000";
  45.     constant cST : std_logic_vector(5 downto 0) := "110000";
  46.    
  47.     -- Registers --
  48.     constant cR0 : std_logic_vector(2 downto 0) := "000";
  49.     constant cR1 : std_logic_vector(2 downto 0) := "001";
  50.     constant cR2 : std_logic_vector(2 downto 0) := "010";
  51.     constant cR3 : std_logic_vector(2 downto 0) := "011";
  52.     constant cR4 : std_logic_vector(2 downto 0) := "100";
  53.     constant cR5 : std_logic_vector(2 downto 0) := "101";
  54.     constant cR6 : std_logic_vector(2 downto 0) := "110";
  55.     constant cR7 : std_logic_vector(2 downto 0) := "111";  
  56.     constant cRX : std_logic_vector(2 downto 0) := "---"; -- reg field not used
  57.    
  58. begin
  59.  process(iA)begin
  60.     case (iA)is
  61.    
  62. --loopA:
  63.             when "00000"=> oQ<= cLD &cR5 &cRX &cR5;
  64.             when "00001" =>  oQ<= cINC &cR5 &cR5 &cRX;
  65.             when "00010" =>  oQ<= cASHL &cR5 &cR5 &cRX;
  66.             when"00011" =>oQ<= cINC &cR5 &cR5 &cRX; --R5=3=Q
  67.            
  68.             when"00100" =>oQ<= cDEC &cR5 &cR5 &cRX;
  69.             when "00101" => oQ<= cJMPZ &"000000000";
  70.            
  71. --loopB:       
  72.             when "00110" => oQ<= cLD &cR6 &cRX &cR6;
  73.             when "00111" => oQ<= cINC &cR6 &cR6 &cRX;
  74.             when "01000" => oQ<= cASHL &cR6 &cR6 &cRX; --R6=2=X
  75.            
  76.             --when "01001"=> oQ<= cLD &cR7 &cRX &cR7;  
  77.             when "01001"=>oQ<= cINC &cR7 &cR7 &cRX; --R7=1=C
  78.             when "01010"=> oQ<= cASHL &cR7 &cR7 &cRX;
  79.            
  80.  
  81.            
  82.             when "01011"=>oQ<= cMOV &cR1 &cR6 &cRX; --R1=X=2
  83.             when "01100"=>oQ<= cASHL &cR4 &cR1 &cRX; --R1*2
  84.             when "01101"=>oQ <= cMOV &cR2 &cR4 &cRX; --R2=2*R1
  85.             when "01110"=>oQ<= cDEC &cR7 &cR7 &cRX;
  86.             when "01111" =>     oQ<= cJMPZ &"000010110";
  87. --do_false:
  88.             when "10000" =>oQ<= cASHR &cR2 &cR2 &cRX;
  89.             when "10001" =>oQ<= cASHR &cR2 &cR2 &cRX;
  90.             when "10010"=> oQ<= cDEC &cR2 &cR2 &cRX;
  91.             when "10011"=> oQ<= cDEC &cR2 &cR2 &cRX;
  92.             when "10100"=> oQ<= cMOV &cR3 &cR2 &cRX;
  93.             when "10101"=> oQ<= cJMP &"000000000";
  94. --do_true:
  95.             when "10110"=> oQ<= cINC &cR3 &cR3 &cRX;
  96.             when "10111"=> oQ<= cINC &cR3 &cR3 &cRX;
  97.             when "11000"=> oQ<= cINC &cR3 &cR3 &cRX;
  98.             when "11001"=> oQ<= cASHL &cR3 &cR3 &cRX;
  99.             when "11010"=> oQ<= cASHL &cR3 &cR3 &cRX; --R3=12
  100.             when "11011"=> oQ<= cJMP &"000000110";
  101.     when others => oQ<= (others => '0');
  102.  
  103.     end case;
  104. end process;     
  105.  
  106. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement