library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
+--use ieee.std_logic_arith.all;
entity alu is
generic ( dsize : integer := 8
alu_en_n : in std_logic;
instruction : in std_logic_vector (dsize - 1 downto 0);
int_d_bus : inout std_logic_vector (dsize - 1 downto 0);
- acc_in : in std_logic_vector (dsize - 1 downto 0);
- acc_out : out std_logic_vector (dsize - 1 downto 0);
+ alu_in : in std_logic_vector (dsize - 1 downto 0);
+ alu_out : out std_logic_vector (dsize - 1 downto 0);
carry_in : in std_logic;
negative : out std_logic;
zero : out std_logic;
begin
- alu_p : process (alu_en_n)
+ alu_p : process (alu_en_n, instruction, alu_in, int_d_bus, carry_in)
variable res : std_logic_vector (dsize - 1 downto 0);
procedure set_n (data : in std_logic_vector (dsize - 1 downto 0)) is
d_print("adc");
elsif instruction (7 downto 5) = "110" then
d_print("cmp");
+ --cmpare A - M.
--set n/v/z flag
- res := acc_in - int_d_bus;
+ res := alu_in - int_d_bus;
set_n(res);
set_z(res);
--ovf flag set when acc < mem .
--no register update.
int_d_bus <= (others => 'Z');
- acc_out <= (others => 'Z');
+ alu_out <= (others => 'Z');
carry_out <= 'Z';
elsif instruction (7 downto 5) = "111" then
end if; --if instruction (1 downto 0) = "01"
else
int_d_bus <= (others => 'Z');
- acc_out <= (others => 'Z');
+ alu_out <= (others => 'Z');
negative <= 'Z';
zero <= 'Z';
carry_out <= 'Z';
alu_we_n : in std_logic;
d_oe_n : in std_logic;
int_dbus : inout std_logic_vector (dsize - 1 downto 0);
- alu_in : in std_logic_vector (dsize - 1 downto 0);
- alu_out : out std_logic_vector (dsize - 1 downto 0)
+ alu_out : in std_logic_vector (dsize - 1 downto 0);
+ alu_in : out std_logic_vector (dsize - 1 downto 0)
);
end accumulator;
begin
we_n <= (d_we_n and alu_we_n);
d <= int_dbus when d_we_n = '0' else
- alu_in when alu_we_n = '0' else
+ alu_out when alu_we_n = '0' else
(others => 'Z');
int_dbus <= q when d_oe_n = '0' else
(others => 'Z');
- alu_out <= q;
+ alu_in <= q;
--read from i/o to cpu
dff_inst : dff generic map (dsize)
alu_en_n : in std_logic;
instruction : in std_logic_vector (dsize - 1 downto 0);
int_d_bus : inout std_logic_vector (dsize - 1 downto 0);
- acc_in : in std_logic_vector (dsize - 1 downto 0);
- acc_out : out std_logic_vector (dsize - 1 downto 0);
+ alu_in : in std_logic_vector (dsize - 1 downto 0);
+ alu_out : out std_logic_vector (dsize - 1 downto 0);
carry_in : in std_logic;
negative : out std_logic;
zero : out std_logic;
alu_we_n : in std_logic;
d_oe_n : in std_logic;
int_dbus : inout std_logic_vector (dsize - 1 downto 0);
- alu_in : in std_logic_vector (dsize - 1 downto 0);
- alu_out : out std_logic_vector (dsize - 1 downto 0)
+ alu_out : in std_logic_vector (dsize - 1 downto 0);
+ alu_in : out std_logic_vector (dsize - 1 downto 0)
);
end component;
acc_reg : accumulator generic map (dsize)
port map(trigger_clk,
acc_d_we_n, acc_alu_we_n, acc_d_oe_n,
- internal_dbus, alu_in, alu_out);
+ internal_dbus, alu_out, alu_in);
-- clock generate.
phi1 <= input_clk;