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

Subversion Repositories opencpu32

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

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
--! 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
                        when alu_sum =>
35 9 leonardoar
                                --Sum operation
36 8 leonardoar
                                S <= A + B;
37
 
38
                        when alu_sub =>
39 9 leonardoar
                                --Subtraction operation
40 8 leonardoar
                                S <= A - B;
41
 
42
                        when alu_inc =>
43 9 leonardoar
                                --Increment operation
44
                                S <= A + conv_std_logic_vector(1, n+1);
45 8 leonardoar
 
46
                        when alu_dec =>
47 9 leonardoar
                                --Decrement operation
48
                                S <= A - conv_std_logic_vector(1, n+1);
49
 
50
                        when alu_mul =>
51
                                --Multiplication operation
52
                                S <= A * B;
53 8 leonardoar
 
54
                        when alu_and =>
55 9 leonardoar
                                --And operation
56 8 leonardoar
                                S <= A and B;
57
 
58
                        when alu_or =>
59 9 leonardoar
                                --Or operation
60 8 leonardoar
                                S <= A or B;
61
 
62
                        when alu_xor =>
63 9 leonardoar
                                --Xor operation
64
                                S <= A xor B;
65
 
66
                        when alu_not =>
67
                                --Not operation
68
                                S <= not A;
69 8 leonardoar
 
70
                        when others =>
71
                                S <= (others => 'Z');
72
                end case;
73
        end process;
74 5 leonardoar
 
75
end Behavioral;
76
 

powered by: WebSVN 2.1.0

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