Line 12... |
Line 12... |
|
|
--! ALU is a digital circuit that performs arithmetic and logical operations.
|
--! ALU is a digital circuit that performs arithmetic and logical operations.
|
|
|
--! ALU is a digital circuit that performs arithmetic and logical operations. It's the fundamental part of the CPU
|
--! ALU is a digital circuit that performs arithmetic and logical operations. It's the fundamental part of the CPU
|
entity Alu is
|
entity Alu is
|
generic (n : integer := nBits - 1);
|
generic (n : integer := nBits - 1); --! Generic value (Used to easily change the size of the Alu on the package)
|
Port ( A : in STD_LOGIC_VECTOR (n downto 0); --! Alu Operand 1
|
Port ( A : in STD_LOGIC_VECTOR (n downto 0); --! Alu Operand 1
|
B : in STD_LOGIC_VECTOR (n downto 0); --! Alu Operand 2
|
B : in STD_LOGIC_VECTOR (n downto 0); --! Alu Operand 2
|
S : out STD_LOGIC_VECTOR (n downto 0); --! Alu Output
|
S : out STD_LOGIC_VECTOR (n downto 0); --! Alu Output
|
sel : in aluOps); --! Select operation
|
sel : in aluOps); --! Select operation
|
end Alu;
|
end Alu;
|
|
|
--! @brief Architure definition of the ALU
|
--! @brief Arithmetic logic unit, refer to this page for more information http://en.wikipedia.org/wiki/Arithmetic_logic_unit
|
--! @details More details about this mux element.
|
--! @details This circuit will be excited by the control unit to perfom some arithimetic, or logic operation (Depending on the opcode selected)
|
|
--! You can see some samples on the Internet: http://www.vlsibank.com/sessionspage.asp?titl_id=12222
|
architecture Behavioral of Alu is
|
architecture Behavioral of Alu is
|
|
|
begin
|
begin
|
--! Behavior description of combinational circuit (Can not infer any FF(Flip flop))
|
--! Behavior description of combinational circuit (Can not infer any FF(Flip flop)) of the Alu
|
process (A,B,sel) is
|
process (A,B,sel) is
|
begin
|
begin
|
case sel is
|
case sel is
|
when alu_sum =>
|
when alu_sum =>
|
|
--Sum operation
|
S <= A + B;
|
S <= A + B;
|
|
|
when alu_sub =>
|
when alu_sub =>
|
|
--Subtraction operation
|
S <= A - B;
|
S <= A - B;
|
|
|
when alu_inc =>
|
when alu_inc =>
|
S <= A - B;
|
--Increment operation
|
|
S <= A + conv_std_logic_vector(1, n+1);
|
|
|
when alu_dec =>
|
when alu_dec =>
|
S <= A - B;
|
--Decrement operation
|
|
S <= A - conv_std_logic_vector(1, n+1);
|
|
|
|
when alu_mul =>
|
|
--Multiplication operation
|
|
S <= A * B;
|
|
|
when alu_and =>
|
when alu_and =>
|
|
--And operation
|
S <= A and B;
|
S <= A and B;
|
|
|
when alu_or =>
|
when alu_or =>
|
|
--Or operation
|
S <= A or B;
|
S <= A or B;
|
|
|
when alu_xor =>
|
when alu_xor =>
|
|
--Xor operation
|
S <= A xor B;
|
S <= A xor B;
|
|
|
|
when alu_not =>
|
|
--Not operation
|
|
S <= not A;
|
|
|
when others =>
|
when others =>
|
S <= (others => 'Z');
|
S <= (others => 'Z');
|
end case;
|
end case;
|
end process;
|
end process;
|
|
|