Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.30 KB | None | 0 0
  1. ---------------------------------------------------------------------------------------
  2. -- Company: CPE 233
  3. -- Engineer: Zach Bunce, Kaioli Bessert, and Garrett Maxon
  4. --
  5. -- Create Date: 02/11/2017 03:59:55 PM
  6. -- Design Name: Stack Pointer
  7. -- Module Name: SP - Counter
  8. -- Project Name: Experiment 8 - Get 'er Done
  9. -- Description: 8-bit Stack Pointer which either loads in a value, increments or
  10. -- decrements the previous pointer value, or resets the pointer to 0 based off of the
  11. -- CPU control lines.
  12. ---------------------------------------------------------------------------------------
  13.  
  14. LIBRARY IEEE;
  15. USE IEEE.STD_LOGIC_1164.ALL;
  16. USE IEEE.STD_LOGIC_ARITH.ALL;
  17. USE IEEE.STD_LOGIC_UNSIGNED.ALL;
  18.  
  19.  
  20. ENTITY SP is
  21.     PORT (
  22.             RST   : in  STD_LOGIC;
  23.             LD    : in  STD_LOGIC;
  24.             INCR  : in  STD_LOGIC;
  25.             DECR  : in  STD_LOGIC;
  26.             D_IN  : in  STD_LOGIC_VECTOR (7 downto 0);
  27.             CLK   : in  STD_LOGIC;
  28.             D_OUT : out STD_LOGIC_VECTOR (7 downto 0)
  29.          );
  30. END SP;
  31.  
  32. ARCHITECTURE Counter of SP is
  33.     -- Sets up a intermediary wire to allow for incrementation.
  34.     SIGNAL D_TEMP : STD_LOGIC_VECTOR (7 downto 0) := (others => '0');
  35.    
  36. BEGIN
  37.     -- Links the temporary data wire to the output line.
  38.     D_OUT <= D_TEMP;
  39.  
  40.     -- Determines the pointer value based off of the control lines.
  41.     countProc: PROCESS(D_IN, LD, INCR, DECR, RST, CLK)
  42.     BEGIN
  43.        
  44.         if(rising_edge(CLK)) then
  45.             -- Resets the pointer to 0x00 when the reset line is high.
  46.             if (RST = '1') then
  47.                 D_TEMP <= x"00";
  48.             -- Sets the output to the input when the load line is high.
  49.             elsif (LD = '1') then
  50.                 D_TEMP <= D_IN;
  51.             -- Increments the output by one when the increment line is high.
  52.             elsif (INCR = '1') then
  53.                 D_TEMP <= (D_TEMP + 1);
  54.             -- Decrements the output by one when the decrement line is high.  
  55.             elsif (DECR = '1') then                                          
  56.                 D_TEMP <= (D_TEMP - 1);                                    
  57.             -- Otherwise, holds the output.
  58.             else
  59.                 D_TEMP <= D_TEMP;
  60.             end if;
  61.         end if;
  62.     END PROCESS countProc;
  63. END Counter;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement