Pico Alu
Pico Alu
entity alu is
Port ( rega : in std_logic_vector(3 downto 0);
regb : in std_logic_vector(3 downto 0);
controls : in std_logic_vector(3 downto 0);
alu_out : out std_logic_vector(3 downto 0);
ccr_out : out std_logic_vector(3 downto 0));
end alu;
begin
process(controls,rega,regb,carry_alu,temp_alu)
begin
case controls is
when "0000" => -- addition opcode
carry_alu <= ( ('0' & rega) + ('0' & regb) ); -- appends zero for
extra bit then adds
C <= carry_alu(4); -- carry out if msb is 1
V <= ( ((rega(3) AND regb(3)) AND not(carry_alu(3)) ) OR
( not(rega(3) OR regb(3)) AND carry_alu(3) ) ); -- if resultant msb different than
operand msbs, V flag set
temp_alu <= rega + regb;
when "0001" => -- subtraction opcode
carry_alu <= ( ('0' & rega) - ('0' & regb) ); -- appends zero for
extra bit then subtracts
C <= carry_alu(4); -- carry out if msb is 1
V <= ( (rega(3) AND not(regb(3))) AND not(carry_alu(3)) ) OR
( ((not(rega(3)) AND regb(3)) AND carry_alu(3)) );
temp_alu <= rega - regb;
when "0010" => -- AND opcode
temp_alu <= rega AND regb;
when "0011" => -- OR opcode
temp_alu <= rega OR regb;
when "0100" => -- rega's complement opcode
temp_alu <= not(rega);
when "0101" => -- rega load opcode
temp_alu <= rega;
when others =>
temp_alu <= "0000"; -- default value
end case;
end process;
end Behavioral;