OpenCores
URL https://opencores.org/ocsvn/opencpu32/opencpu32/trunk

Subversion Repositories opencpu32

[/] [opencpu32/] [trunk/] [hdl/] [opencpu32/] [Alu.vhd] - Blame information for rev 16

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 leonardoar
--! @file
2
--! @brief Arithmetic logic unit http://en.wikipedia.org/wiki/Arithmetic_logic_unit
3
 
4 8 leonardoar
--! Use standard library and import the packages (std_logic_1164,std_logic_unsigned,std_logic_arith)
5 5 leonardoar
library IEEE;
6 8 leonardoar
use ieee.std_logic_1164.all;
7
use ieee.std_logic_unsigned.all;
8
use ieee.std_logic_arith.all;
9 5 leonardoar
 
10
--! Use CPU Definitions package
11 8 leonardoar
use work.pkgOpenCPU32.all;
12 5 leonardoar
 
13
--! ALU is a digital circuit that performs arithmetic and logical operations.
14
 
15
--! ALU is a digital circuit that performs arithmetic and logical operations. It's the fundamental part of the CPU
16
entity Alu is
17 9 leonardoar
    generic (n : integer := nBits - 1);                                 --! Generic value (Used to easily change the size of the Alu on the package)
18 8 leonardoar
         Port ( A : in  STD_LOGIC_VECTOR (n downto 0);           --! Alu Operand 1
19
           B : in  STD_LOGIC_VECTOR (n downto 0);                --! Alu Operand 2
20
           S : out  STD_LOGIC_VECTOR (n downto 0);               --! Alu Output
21
           sel : in  aluOps);                                                                   --! Select operation
22 5 leonardoar
end Alu;
23
 
24 9 leonardoar
--! @brief Arithmetic logic unit, refer to this page for more information http://en.wikipedia.org/wiki/Arithmetic_logic_unit
25
--! @details This circuit will be excited by the control unit to perfom some arithimetic, or logic operation (Depending on the opcode selected)
26 10 leonardoar
--! \n You can see some samples on the Internet: http://www.vlsibank.com/sessionspage.asp?titl_id=12222
27 5 leonardoar
architecture Behavioral of Alu is
28
 
29
begin
30 9 leonardoar
        --! Behavior description of combinational circuit (Can not infer any FF(Flip flop)) of the Alu
31 8 leonardoar
        process (A,B,sel) is
32
        begin
33
                case sel is
34 16 leonardoar
                        when alu_pass =>
35
                                --Pass operation
36
                                S <= A;
37
 
38 8 leonardoar
                        when alu_sum =>
39 9 leonardoar
                                --Sum operation
40 8 leonardoar
                                S <= A + B;
41
 
42
                        when alu_sub =>
43 9 leonardoar
                                --Subtraction operation
44 8 leonardoar
                                S <= A - B;
45
 
46
                        when alu_inc =>
47 9 leonardoar
                                --Increment operation
48
                                S <= A + conv_std_logic_vector(1, n+1);
49 8 leonardoar
 
50
                        when alu_dec =>
51 9 leonardoar
                                --Decrement operation
52
                                S <= A - conv_std_logic_vector(1, n+1);
53
 
54
                        when alu_mul =>
55
                                --Multiplication operation
56
                                S <= A * B;
57 8 leonardoar
 
58
                        when alu_and =>
59 9 leonardoar
                                --And operation
60 8 leonardoar
                                S <= A and B;
61
 
62
                        when alu_or =>
63 9 leonardoar
                                --Or operation
64 8 leonardoar
                                S <= A or B;
65
 
66
                        when alu_xor =>
67 9 leonardoar
                                --Xor operation
68
                                S <= A xor B;
69
 
70
                        when alu_not =>
71
                                --Not operation
72
                                S <= not A;
73 8 leonardoar
 
74
                        when others =>
75
                                S <= (others => 'Z');
76
                end case;
77
        end process;
78 5 leonardoar
 
79
end Behavioral;
80
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.