uikolas

antras komp architektura

Mar 7th, 2014
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 12.00 KB | None | 0 0
  1. --pasikeisti skiltis       
  2. --Operacinio itaiso (priverstinei adresacijai)
  3. library ieee;
  4. use ieee.std_logic_1164.all;
  5. use ieee.numeric_std.all;
  6. use IEEE.STD_LOGIC_UNSIGNED.all;
  7.  
  8. entity operacinis is
  9. port (  Y   :   in  std_logic_vector(1 to 17);
  10.     clock   :   in  std_logic;
  11.     reset   :   in  std_logic;
  12.        X    :   out std_logic_vector(1 to 2);
  13.      Duom   :   in  std_logic_vector( 7 downto 0) := "00000000";
  14.       Rez   :   out std_logic_vector(14 downto 0)
  15.       );
  16. end operacinis;
  17. -----------------------------------------------------
  18. architecture ALU of operacinis is
  19.  
  20. begin
  21.     process (reset,clock)
  22.         variable A : std_logic_vector(14 downto 0);
  23.         variable L : std_logic_vector(6 downto 0);
  24.         variable M : std_logic_vector(6 downto 0);
  25.         variable B : std_logic_vector( 7 downto 0);
  26.         variable C : std_logic_vector(14 downto 0);
  27.         variable Sk: integer range 0 to 7;
  28.     begin
  29.         if reset= '1' then
  30.            C  := "000000000000000";  -- clear sandauga
  31.            A  := "000000000000000";  -- clear A
  32.            L  := "0000000";
  33.            M  := "0000000";
  34.            B  := "00000000";       -- clear B
  35.            X  <= "00";             -- clear LS
  36.       elsif clock'event and clock = '1' then   
  37.         ------------------------------------------------------------  
  38.        
  39.         if    Y(1) = '1' then
  40.             A(7 downto 0)  := Duom;   --  load  A  
  41.             A(14 downto 7) := "00000000";--"11111111"; -- uzpildo kaire puse
  42.         end if;  
  43.         ---------------------------------------------
  44.         if    Y(2) = '1' then
  45.             B  := Duom;   --  load  B
  46.             --X(1) <= B(7);
  47.             C  := "000000000000000";  -- clear C
  48.             Sk  := 7;   --  load  Sk
  49.         end if;
  50.         ---------------------------------------------  
  51.        
  52.        
  53.         ---------------------------------------------
  54.         if    Y(3) = '1' then
  55.             L := A(6 downto 0);
  56.         end if;
  57.         ---------------------------------------------
  58.         if    Y(4) = '1' then
  59.             M(6 downto 0) := not L + 1;  
  60.         end if;
  61.         ---------------------------------------------
  62.         if    Y(5) = '1' then    
  63.             A(6 downto 0) := M;
  64.         end if;  
  65.         ---------------------------------------------  
  66.        
  67.        
  68.         ---------------------------------------------
  69.         if    Y(6) = '1' then
  70.             X(1) <= B(7); -- ar auksciausia skiltis = 1, jei taip, darom adresas + 1
  71.         end if;    
  72.         ---------------------------------------------
  73.         if    Y(7) = '1' then
  74.             C  := C + A;
  75.         end if;
  76.         ---------------------------------------------
  77.         if    Y(8) = '1' then  
  78.              B  := B(6 downto 0) & '0';   --  shift  B to left
  79.              C  := C(13 downto 0) & '0';  --  shift  C to left
  80.              --X(1) <= B(7); -- jei B(7) = 1, tai X(1) = 1    
  81.         end if;    
  82.         ---------------------------------------------
  83.         if    Y(9) = '1' then  
  84.             if Sk > 0 then
  85.                 Sk  := Sk - 1;   --  decrement Sk
  86.                 X(2) <= '1';
  87.             else
  88.                 X(2) <= '0';
  89.             end if;
  90.         end if;
  91.         ---------------------------------------------  
  92.        
  93.        
  94.         ---------------------------------------------
  95.         if    Y(16) = '1' then  
  96.             C := '0' & C(14 downto 1);   -- Grazina C vienu atgal
  97.             Rez <= C;
  98.         end if;        
  99.         ---------------------------------------------
  100.         if    Y(17) = '1' then
  101.             assert 1 = 0 report "Modeliavimas baigtas" severity failure;
  102.         end if;
  103.        
  104.         ------------------------------------------------------------
  105.   end if;
  106. end process;
  107. end ALU;
  108.  
  109. -- ALU
  110.  
  111. --////////////////////////////////////////////////////////////////////////////////////////////////////
  112. --Mikroprograminio valdymo itaiso komponentai----------------------------------------------------------------------------------------------------------------------
  113.     -- id1
  114.     --mikrokomandu atmint? MK_ROM,
  115.     --i? kurios pagal suformuot? paskesn?s MK adres? (Next_MK) i?renkama mikrokomanda (Mikrokom);
  116.    
  117. library ieee;
  118. use ieee.std_logic_1164.all;
  119. use ieee.std_logic_arith.all;        
  120. use ieee.std_logic_unsigned.all;
  121.  
  122. entity MK_ROM is
  123. port( Clock : in  std_logic;
  124.     next_MK : in  std_logic_vector(0 to 3);
  125.    Mikrokom : out std_logic_vector(1 to 23)
  126.     );
  127. end MK_ROM;
  128. --------------------------------------------------------
  129. architecture MK_Atmintis of MK_ROM is
  130.  
  131.     type MK_Array is array (0 to 30) of std_logic_vector(1 to 23);
  132.  
  133.     constant Content: MK_Array := (  
  134.         -- X(1) = 01 , X(2) = 10
  135.         -- paskutiniai 4 rodo i kur (priekinis adresas nurodo i kur)
  136.     -- ADR
  137.         0 => "10000000000000000000001", --Y(1)
  138.         1 => "01000000000000000000011", --Y(2) atjungtas 2 adresas, keliauja i 3 iskart
  139.  
  140.         --2 => "00111000000000000000011", -- Y(3), Y(4), Y(5) | A pavertimas i papildoma koda
  141.        
  142.         3 => "00000100000000000010100", -- Y(6) tikrina pirma reiksme, jeigu = 1, tai persokam i sudeti /// jeigu noredemi, kad keliautu i 100, keliaus tada i 101
  143.         4 => "00000001000000000000110", -- Y(8) postumis  
  144.         5 => "00000010000000000000100", -- Y(7) sudetis, butinai turi pereiti i 4 vel i postumi
  145.         6 => "00000000100000000100111", -- Y(9) sk - 1 ir X(2)
  146.         7 => "00000000000000010001001", -- Y(16)rez = c
  147.         8 => "00000000000000000000011", -- ciiiiiiiiiiiiiiiiiklas, kai sk <> 0, griztam i 3 adresa
  148.         9 => "00000000000000001001001", -- Y(17) stabdo viska
  149.        
  150.         10 => "00000000000000000000000",
  151.        11 => "00000000000000000000000",
  152.        12 => "00000000000000000000000",
  153.        13 => "00000000000000000000000",
  154.        
  155.         --8 => "0000000010001010", --Y(9)
  156.         --9 => "0000000001001010", --Y(10)
  157.  
  158. --ciklas be sudeties
  159. --5 => "0000001000000111", --Y(6)  postumiai
  160. --6 => "0000010000000110", --Y(7)  sudetis
  161. --7 => "0000000100100100", --Y(8)  sk - 1          
  162.    OTHERS => "00000000000000000000000"     
  163. );      
  164.  
  165. begin MK_skaitymas:
  166.     process (Clock, next_MK)
  167.     begin
  168.        if ( Clock'event and Clock = '1' ) then
  169.       Mikrokom <= Content(conv_integer(next_MK));
  170.        end if;
  171.     end process;
  172. end MK_Atmintis;
  173.  
  174. --////////////////////////////////////////////////////////////////////////////////////////////////////
  175.     -- id2
  176.     --mikrokomandu skirstymo schem? MK_Form,
  177.     --kurioje nauja mikrokomanda (Mikrokom) padalijama ? tris laukus - mikrooperaciju lauk? (Y),
  178.     --login?s s?lygos numerio lauk? (LS) ir adreso lauk? (Addr), skirt? paskesn?s MK adresui formuoti;
  179.  
  180. library ieee;
  181. use ieee.std_logic_1164.all;
  182. use ieee.numeric_std.all;
  183.  
  184. Entity MK_Form is
  185. port (  
  186.    Mikrokom : in  std_logic_vector(1 to 23);
  187.     Y   : out std_logic_vector(1 to 17);
  188.     LS  : out std_logic_vector(0 to 1);
  189.     Addr    : out std_logic_vector(0 to 3)
  190.        );
  191. end  MK_Form;
  192. -------------------------------------------------------------
  193. architecture Skirstymas of  MK_Form is
  194. begin
  195.        Y    <= Mikrokom(1 to 17);
  196.        LS   <= Mikrokom(18 to 19);
  197.        Addr <= Mikrokom(20 to 23);
  198. end Skirstymas;
  199.  
  200. --////////////////////////////////////////////////////////////////////////////////////////////////////
  201.     -- id3
  202.     --paskesn?s mikrokomandos adreso formavimo schem? MK_AR_Form,
  203.     --kuri pagal mikrokomandoje esan?i? informacij? (LS, Addr) ir (jei to reikia) tikrinamos
  204.     --login?s s?lygos (LS_Values) reik?me formuoja paskesn?s MK adres? (next_MKAdr);  
  205.    
  206. library ieee;
  207. use ieee.std_logic_1164.all;
  208. use ieee.std_logic_arith.all;        
  209. use ieee.numeric_std.all;
  210. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  211.  
  212. Entity MK_AR_Form is
  213. port(    LS : in  std_logic_vector(0 to 1);
  214.    LS_values    : in  std_logic_vector(1 to 2);
  215.         Addr    : in  std_logic_vector(0 to 3);
  216.     next_Adr    : out std_logic_vector(0 to 3);
  217.        clock    : in  std_logic
  218.     );
  219. end  MK_AR_Form;
  220. ---------------------------------------------------------
  221. architecture Behav of  MK_AR_Form is
  222.  
  223. begin process (clock)
  224.    variable xx : integer;
  225. begin
  226.      xx := conv_integer(LS);
  227.      if (clock'event and clock='1') then
  228.      if (xx = 0) then
  229.            next_Adr <= Addr;
  230.      elsif (LS_values(xx)='0') then
  231.            next_Adr <= Addr;
  232.      elsif (LS_values(xx)='1') then
  233.            next_Adr <= Addr +'1';
  234.      end if;
  235.      end if;
  236.    end process;
  237. end Behav;
  238.  
  239. --////////////////////////////////////////////////////////////////////////////////////////////////////
  240.     -- id4
  241.     --mikrokomandos adreso registr? MK_AR, kuriame saugomas i?renkamos mikrokomandos adresas (MK_Addr).
  242.  
  243. library ieee;
  244. use ieee.std_logic_1164.all;
  245. use ieee.numeric_std.all;
  246.  
  247. Entity MK_AR is
  248. port (  Clock : in  std_logic;
  249.         Reset : in  std_logic;
  250.    next_MKAdr : in  std_logic_vector(0 to 3);
  251.       MK_Addr : out std_logic_vector(0 to 3)
  252. );
  253. end MK_AR;
  254. ------------------------------------------------------------
  255. architecture Behav of MK_AR is
  256.  begin
  257.  process (Reset, clock)
  258.    begin
  259.        if (Reset = '1') then
  260.           MK_Addr <= "0000";
  261.        elsif (clock'event and clock='1') then
  262.              MK_Addr <= next_MKAdr;
  263.        end if;
  264.    end process;
  265. end Behav;
  266.  
  267.  
  268. --////////////////////////////////////////////////////////////////////////////////////////////////////
  269. --Mikroprograminio valdymo komponentu apjungimas----------------------------------------------------------------------------------------------------------------------
  270.  
  271. library ieee;
  272. use ieee.std_logic_1164.all;
  273. use ieee.numeric_std.all;
  274.  
  275. entity ProgLog_top is
  276.     port(
  277.      sinchr1 : in std_logic;
  278.      sinchr2 : in std_logic;
  279.      sinchr3 : in std_logic;
  280.      sinchr4 : in std_logic;
  281.      prad    : in std_logic;
  282.         Data : in  std_logic_vector( 7 downto 0);  -- operandai
  283.         Res  : out std_logic_vector(14 downto 0)   -- sandauga  
  284.      );
  285. end ProgLog_top;
  286.  
  287. architecture struktura of ProgLog_top is
  288. -------------------------------------------
  289. --- komponentai                          ---
  290. -------------------------------------------
  291. component MK_ROM is
  292. port(  Clock: in std_logic;
  293.     next_MK : in std_logic_vector(0 to 3);
  294.     Mikrokom: out std_logic_vector(1 to 23)
  295.     );
  296. end component;
  297.  
  298. component MK_AR is
  299. port(   Clock : in std_logic;
  300.         Reset : in std_logic;
  301.    next_MKAdr : in std_logic_vector(0 to 3);
  302.       MK_Addr : out std_logic_vector(0 to 3)
  303. );
  304. end component;
  305.  
  306. component MK_AR_Form is
  307. port(   LS  : in  std_logic_vector(0 to 1);
  308.   LS_values : in  std_logic_vector(1 to 2);
  309.       Addr  : in  std_logic_vector(0 to 3);
  310.    next_Adr : out std_logic_vector(0 to 3);
  311.       clock : in  std_logic
  312. );
  313. end component;
  314.  
  315. component MK_Form is
  316. port(  
  317.     Mikrokom: in  std_logic_vector(1 to 23);
  318.        Y    : out std_logic_vector(1 to 17);
  319.        LS   : out std_logic_vector(0 to 1);
  320.        Addr : out std_logic_vector(0 to 3)
  321. );
  322. end component;
  323.  
  324. component operacinis is
  325. port(   Y   : in std_logic_vector(1 to 17);
  326.     clock   :   in  std_logic;
  327.     reset   :   in  std_logic;
  328.         X   :   out std_logic_vector(1 to 2);
  329.     Duom    :   in  std_logic_vector( 7 downto 0) := "00000000";
  330.       Rez   :   out std_logic_vector(14 downto 0)
  331.   );
  332. end component;
  333.  
  334.  
  335. -------------------------------------------
  336. --- Sujungimams                         ---
  337. -------------------------------------------
  338. signal logsnr   :   std_logic_vector(0 to 1);  -- log. sal. nr.
  339. signal log_sal  :   std_logic_vector(1 to 2);  -- logines salygos
  340. signal mops     :   std_logic_vector(1 to 17); -- mikrooperacijos
  341. signal mk       :   std_logic_vector(1 to 23); -- mikrokomanda
  342. signal mkad1    :   std_logic_vector(0 to 3);  -- MK adresas
  343. signal mkad2    :   std_logic_vector(0 to 3);  -- MK adresas
  344. signal mkad3    :   std_logic_vector(0 to 3);  -- MK adresas
  345.  
  346. begin
  347.  
  348. ALU1: operacinis port map (
  349.     Y       => mops,
  350.     clock => sinchr3,
  351.     reset => prad,
  352.     X     => log_sal,
  353.     Duom  => Data,
  354.     Rez   => Res
  355.    );
  356.    
  357. Vald1: MK_ROM port map(
  358.       Clock => sinchr2,
  359.     next_MK => mkad1,
  360.     Mikrokom => mk
  361.     );
  362.  
  363. Vald2: MK_AR port map(
  364.       Clock => sinchr1,
  365.       Reset => prad,
  366.     next_MKAdr=> mkad3,
  367.     MK_Addr => mkad1
  368.     );
  369.  
  370. Vald3: MK_AR_Form port map (
  371.     LS  => logsnr,
  372.     LS_values=> log_sal,
  373.     Addr    => mkad2,
  374.     next_Adr    => mkad3,
  375.     clock   => sinchr4
  376. );
  377.  
  378.   Vald4: MK_Form port map (  
  379.     Mikrokom    => mk,
  380.     Y       => mops,
  381.     LS  => logsnr,
  382.     Addr    => mkad2
  383. );
  384. end struktura;
  385.  
  386.  
  387. --      0 => "1000000000000001", --Y(1) --> Y(2)
  388. --      1 => "0100000000010101", --Y(2) --> Y(3)
  389. --      --1 => "0100000000010010", --Y(2) --> Y(3)
  390. --
  391. --      --2 => "0010000000000011", --Y(3) --> Y(4)
  392. --      --3 => "0001000000000100", --Y(4) --> Y(5)
  393. --      --4 => "0000100000000101", --Y(5) --> Y(6)
  394. --
  395. --      5 => "0000001000000110", --Y(6) --> Y(7) sudetis
  396. --      6 => "0000010000000111", --Y(7) --> Y(8) postumis
  397. --      7 => "0000000100100100", --Y(8) --> Y(6) sk - 1    
  398. --
  399. --      --8 => "0000000010001010", --Y(9)
  400. --      --9 => "0000000001001010", --Y(10)
Advertisement
Add Comment
Please, Sign In to add comment