スタックを作る

なにがしたいかよく解らんですが、
ゲーム木探索をするためにはスタックを作ることになるだろうってことで、

type stack_type is array   (7 downto 0) of
             std_logic_vector(3 downto 0);

vectorのarrayというのも宣言できるようですね。
リセットした時に配列内にデータをセットしておいて、ボタンを押すとスタックポインタ(dp)を
一つづつ増やしていく感じ。
VHDL実習は、今夜はこのへんにしておきましょう。


「HDL設計入門」桜井至(テクノプレス)しか本を持ってないので
今度本屋で何か買ってみよう。

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity test is

	port
	(
		CLK : in std_logic;
		RESET : in std_logic;
		D : in std_logic;
		E : in std_logic;
		Q_4 : out std_logic_vector(3 downto 0)
	);

end test;

architecture test_Body of test is

type stack_type is array   (7 downto 0) of
             std_logic_vector(3 downto 0);

signal DBUF_4: std_logic_vector(3 downto 0);
signal dp:integer;      --  data stack pointer
signal data_stack            : stack_type;

begin

	process(D)

	begin

		if D'event and D = '0' then
			dp<= dp+1;
			if(dp>=7) then
				dp<=7;
			end if;
		end if;
	
		if RESET = '0' then
			data_stack(0) <= "0000";
			data_stack(1) <= "0001";
			data_stack(2) <= "0010";
			data_stack(3) <= "0011";
			data_stack(4) <= "0100";
			data_stack(5) <= "0101";
			data_stack(6) <= "0110";
			data_stack(7) <= "0111";
			dp <= 0;
		end if;

	end process;

	Q_4 <= not data_stack(dp);

end test_Body;