Advertisement
HimikoWerckmeister

Creg

Apr 2nd, 2015
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.39 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.std_logic_1164.all;
  3. use IEEE.std_logic_arith.all;
  4.  
  5. entity CReg is
  6.     port (data: in std_logic_vector(11 downto 0);
  7.             ld: in std_logic;
  8.             rd: in std_logic;
  9.             clk: in std_logic;
  10.             mbit: out boolean;
  11.             rdy: out boolean);
  12. end entity CReg;
  13.  
  14. architecture behav of CReg is
  15.  
  16. type states is (STO, WT,RET);
  17. signal newstate;
  18.  
  19. begin
  20.  
  21. -- state transition process
  22.     process is
  23.         variable currentstate: states := RET;
  24.     begin
  25.         if clk = '1' then
  26.             case currentstate is
  27.                 when STO =>
  28.                     currentstate := WT;
  29.                 when WT =>
  30.                     if (ld = '1') then
  31.                         currentstate := STO;
  32.                     end if;
  33.                    
  34.                     if not((ld = '1') or (rd = '1')) then
  35.                         currentstate := WT;
  36.                     end if;
  37.                    
  38.                     if ld = '1' then
  39.                         currentstate := STO;
  40.                     end if;
  41.                    
  42.                     if ((ld = '1') and (rd = '1')) then
  43.                         currentstate := RET;
  44.                     end if;
  45.                 when RET =>
  46.                     currentstate := WT;
  47.             end case;
  48.             newstate <= currentstate;
  49.         end if;
  50.     wait on clk;
  51.     end process;
  52. -- asserted output process
  53.     process is
  54.         variable REG: std_logic_vector(11 downto 0);
  55.         variable rdyVar: boolean := false;
  56.         variable mbitVar: boolean := false;
  57.     begin
  58.         case newstate is
  59.             when STO =>
  60.                 REG := data;
  61.             when WT =>
  62.                 rdyVar := true;
  63.             when RET =>
  64.                 mbitVar := (REG = data);
  65.         end case;
  66.         rdy <= rdyVar;
  67.         mbit <= mbitVar;
  68.     wait on newstate;
  69.     end process;
  70.    
  71.    
  72. end behav;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement