diff --git a/firmware/alu/main.vhd b/firmware/alu/main.vhd index 1352b07..318000a 100644 --- a/firmware/alu/main.vhd +++ b/firmware/alu/main.vhd @@ -5,7 +5,8 @@ use ieee.numeric_std.ALL; entity main is generic ( - WIDTH: integer := 8 + WIDTH: integer := 8; + FIRST: boolean := true ); port ( func: in std_logic_vector(3 downto 0); @@ -77,13 +78,21 @@ begin when "1001" => -- INC x <= accu; y <= (others => '0'); - cin <= '1'; + if FIRST then + cin <= '1'; + else + cin <= carry_in; + end if; result <= sum; carry_out <= cout; when "1010" => -- DEC x <= accu; y <= (others => '1'); - cin <= '0'; + if FIRST then + cin <= '0'; + else + cin <= not carry_in; + end if; result <= sum; carry_out <= not cout; when "1011" => -- ZERO diff --git a/firmware/alu/tests/toy_16.vhd b/firmware/alu/tests/toy_16.vhd index ee0fc1d..84f0ccf 100644 --- a/firmware/alu/tests/toy_16.vhd +++ b/firmware/alu/tests/toy_16.vhd @@ -11,6 +11,9 @@ architecture test of toy_16 is constant period: time := 1us; component main + generic ( + FIRST: boolean + ); port ( func: in std_logic_vector(3 downto 0); accu: in std_logic_vector(7 downto 0); @@ -43,7 +46,9 @@ architecture test of toy_16 is begin - alu1: main port map ( + alu1: main generic map ( + FIRST => true + ) port map ( func => func, accu => accu(7 downto 0), ram => ram(7 downto 0), @@ -52,7 +57,9 @@ begin carry_out => carry_propagation ); - alu2: main port map ( + alu2: main generic map ( + FIRST => false + ) port map ( func => func, accu => accu(15 downto 8), ram => ram(15 downto 8),