uikolas

pirmo ANTRAS

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