library ieee; use ieee.numeric_bit.all; architecture behavior of alu is begin alu_op: process ( s1, s2, func ) is procedure add ( L, R : in dlx_word; result : out dlx_word; overflow : out bit; carry_in : in bit; signed : in boolean) is variable carry : bit := carry_in; variable carry_prev : bit; begin for index in result'reverse_range loop carry_prev := carry; -- of previous bit result(index) := L(index) xor R(index) xor carry; carry := (L(index) and R(index)) or (carry and (L(index) xor R(index))); end loop; if signed then overflow := carry xor carry_prev; else overflow := carry; end if; end procedure add; variable temp_result : dlx_word; variable temp_overflow : bit; begin temp_overflow := '0'; case func is when alu_pass_s1 => temp_result := s1; when alu_pass_s2 => temp_result := s2; when alu_and => temp_result := s1 and s2; when alu_or => temp_result := s1 or s2; when alu_xor => temp_result := s1 xor s2; when alu_sll => temp_result := s1 sll to_integer(s2(4 downto 0)); when alu_srl => temp_result := s1 srl to_integer(s2(4 downto 0)); when alu_sra => temp_result := s1 sra to_integer(s2(4 downto 0)); when alu_add => add(s1, s2, temp_result, temp_overflow, carry_in => '0', signed => true); when alu_addu => add(s1, s2, temp_result, temp_overflow, carry_in => '0', signed => false); when alu_sub => add(s1, not s2, temp_result, temp_overflow, carry_in => '1', signed => true); when alu_subu => add(s1, not s2, temp_result, temp_overflow, carry_in => '1', signed => false); when others => report "illegal function code" severity error; temp_result := X"0000_0000"; end case; result <= temp_result after Tpd; zero <= bit'val(boolean'pos(temp_result = X"0000_0000")) after Tpd; negative <= temp_result(31) after Tpd; overflow <= temp_overflow after Tpd; end process alu_op; end architecture behavior;