Fix INC and DEC by specifying if alu is the first one
If it is not the first, only increment or decrement when carry or borrow is set.
This commit is contained in:
parent
fdedf7b657
commit
a1bebb977e
@ -5,7 +5,8 @@ use ieee.numeric_std.ALL;
|
|||||||
|
|
||||||
entity main is
|
entity main is
|
||||||
generic (
|
generic (
|
||||||
WIDTH: integer := 8
|
WIDTH: integer := 8;
|
||||||
|
FIRST: boolean := true
|
||||||
);
|
);
|
||||||
port (
|
port (
|
||||||
func: in std_logic_vector(3 downto 0);
|
func: in std_logic_vector(3 downto 0);
|
||||||
@ -77,13 +78,21 @@ begin
|
|||||||
when "1001" => -- INC
|
when "1001" => -- INC
|
||||||
x <= accu;
|
x <= accu;
|
||||||
y <= (others => '0');
|
y <= (others => '0');
|
||||||
cin <= '1';
|
if FIRST then
|
||||||
|
cin <= '1';
|
||||||
|
else
|
||||||
|
cin <= carry_in;
|
||||||
|
end if;
|
||||||
result <= sum;
|
result <= sum;
|
||||||
carry_out <= cout;
|
carry_out <= cout;
|
||||||
when "1010" => -- DEC
|
when "1010" => -- DEC
|
||||||
x <= accu;
|
x <= accu;
|
||||||
y <= (others => '1');
|
y <= (others => '1');
|
||||||
cin <= '0';
|
if FIRST then
|
||||||
|
cin <= '0';
|
||||||
|
else
|
||||||
|
cin <= not carry_in;
|
||||||
|
end if;
|
||||||
result <= sum;
|
result <= sum;
|
||||||
carry_out <= not cout;
|
carry_out <= not cout;
|
||||||
when "1011" => -- ZERO
|
when "1011" => -- ZERO
|
||||||
|
@ -11,6 +11,9 @@ architecture test of toy_16 is
|
|||||||
constant period: time := 1us;
|
constant period: time := 1us;
|
||||||
|
|
||||||
component main
|
component main
|
||||||
|
generic (
|
||||||
|
FIRST: boolean
|
||||||
|
);
|
||||||
port (
|
port (
|
||||||
func: in std_logic_vector(3 downto 0);
|
func: in std_logic_vector(3 downto 0);
|
||||||
accu: in std_logic_vector(7 downto 0);
|
accu: in std_logic_vector(7 downto 0);
|
||||||
@ -43,7 +46,9 @@ architecture test of toy_16 is
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
|
|
||||||
alu1: main port map (
|
alu1: main generic map (
|
||||||
|
FIRST => true
|
||||||
|
) port map (
|
||||||
func => func,
|
func => func,
|
||||||
accu => accu(7 downto 0),
|
accu => accu(7 downto 0),
|
||||||
ram => ram(7 downto 0),
|
ram => ram(7 downto 0),
|
||||||
@ -52,7 +57,9 @@ begin
|
|||||||
carry_out => carry_propagation
|
carry_out => carry_propagation
|
||||||
);
|
);
|
||||||
|
|
||||||
alu2: main port map (
|
alu2: main generic map (
|
||||||
|
FIRST => false
|
||||||
|
) port map (
|
||||||
func => func,
|
func => func,
|
||||||
accu => accu(15 downto 8),
|
accu => accu(15 downto 8),
|
||||||
ram => ram(15 downto 8),
|
ram => ram(15 downto 8),
|
||||||
|
Loading…
Reference in New Issue
Block a user