8-Bit ALU in VHDL

This arithmetic logic unit accepts 8-bit inputs, but it can easily be modded to higher bits. It supports the addition, subtraction, set if less than, AND, and OR operations. The operation to perform is determined by the 3-bit address bus.

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;

ENTITY alu8bit IS
	port(a, b : in std_logic_vector(7 downto 0);	-- a and b are busses
		op : in std_logic_vector(2 downto 0);
		zero : out std_logic;
	    f : out std_logic_vector(7 downto 0));
END alu8bit;

architecture behavioral of alu8bit is
	variable temp: std_logic_vector(7 downto 0);
	case op is
		when "000" =>
			temp := a and b;
		when "100" =>
			temp := a and b;
		when "001" =>
			temp := a or b;
		when "101" =>
			temp := a or b;
		when "010" =>
			temp := a + b;
		when "110" =>
			temp := a - b;
		when "111" =>
			if a < b then
			temp := "11111111";
			temp := "00000000";
			end if;
		when others =>
			temp := a - b;
	end case;
	if temp="00000000" then
	zero <= '1';
	zero <= '0';
	end if;
	f <= temp;
	end process;
end behavioral;


Other Articles That You May Be Interested In:

Something's Gotta Give Movie Review
A review of a movie about an aging playboy who begins to question his philandering lifestyle.
Cystic Fibrosis
This relatively rare, but often fatal, disease produces unhealthy levels of fluid in the lungs.