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

Subversion Repositories mips789

[/] [mips789/] [branches/] [mcupro/] [verilog/] [mips_core/] [alu.v] - Blame information for rev 55

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

Line No. Rev Author Line
1 2 mcupro
//This file is based on YACC ->alu.v 
2
 
3
 
4
 
5
/////////////////////////////////////////////////////////////////////
6
////  Author: Liwei                                              ////
7
////                                                             ////
8
////                                                             ////
9
////  If you encountered any problem, please contact :           ////
10
////  Email: mcupro@yahoo.com.hk or mcupro@opencores.org         ////
11
////                                                             ////
12
////  Downloaded from:                                           ////
13
////     http://www.opencores.org/pdownloads.cgi/list/mips789    ////
14
/////////////////////////////////////////////////////////////////////
15
////                                                             ////
16
//// Copyright (C) 2006-2007 Liwei                               ////
17
////                         mcupro@yahoo.com.hk                 ////
18
////                                                             ////
19
////                                                             ////
20
//// This source file may be used and distributed freely without ////
21
//// restriction provided that this copyright statement is not   ////
22
//// removed from the file and any derivative work contains the  ////
23
//// original copyright notice and the associated disclaimer.    ////
24
////                                                             ////
25
//// Please let the author know if it is used                    ////
26
//// for commercial purpose.                                     ////
27
////                                                             ////
28
////     THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY     ////
29
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED   ////
30
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS   ////
31
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR      ////
32
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,         ////
33
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    ////
34
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE   ////
35
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR        ////
36
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  ////
37
//// LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT  ////
38
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT  ////
39
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE         ////
40
//// POSSIBILITY OF SUCH DAMAGE.                                 ////
41
////                                                             ////
42
/////////////////////////////////////////////////////////////////////
43
////                                                             ////
44
////                                                             ////
45
//// Date of Creation: 2007.8.1                                  ////
46
////                                                             ////
47
//// Version: 0.0.1                                              ////
48
////                                                             ////
49
//// Description:                                                ////
50
////                                                             ////
51
////                                                             ////
52
/////////////////////////////////////////////////////////////////////
53
////                                                             ////
54
//// Change log:                                                 ////
55
////                                                             ////
56
/////////////////////////////////////////////////////////////////////
57
 
58
`define                ALU_ADD      12
59
`define                ALU_ADDU     13
60
`define                ALU_SUB      14
61
`define                ALU_SUBU     15
62
`define                ALU_SLTU     16
63
`define                ALU_SLT      17
64
`define                ALU_OR       18
65
`define                ALU_AND      19
66
`define                ALU_XOR      20
67
`define                ALU_NOR      21
68
`define                ALU_PA       22
69
`define                ALU_PB       23
70
 
71
module alu (a,b,alu_out,alu_func);
72
 
73
    input [31:0] a,b;
74
    output reg [31:0] alu_out;
75
    input [4:0]  alu_func;
76
 
77
    wire [31:0] c;
78
 
79
    reg [32:0] sum;
80
 
81
    always @(*)
82
    begin
83
        case (alu_func)
84
            `ALU_PA     : alu_out=a;
85
            `ALU_PB     : alu_out=b;
86
            `ALU_ADD    : alu_out=a+b;
87
            `ALU_SUB  ,
88
            `ALU_SUBU      : alu_out=a + (~b)+1;
89
            `ALU_OR     : alu_out=a | b;
90
            `ALU_AND     : alu_out=a & b;
91
            `ALU_XOR       : alu_out=a ^ b;
92
            `ALU_NOR        : alu_out=~(a | b);
93
            `ALU_SLTU : alu_out=(a < b)?1:0;
94
            `ALU_SLT :
95
            begin
96
                sum={a[31],a}+~{b[31],b}+33'h0_0000_0001;
97
                alu_out={31'h0000_0000,sum[32]};
98
            end
99
            default : alu_out=32'h0;
100
        endcase
101
    end
102
endmodule
103
 
104
/*
105
this file is based on YACC's alu.v
106
*/

powered by: WebSVN 2.1.0

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