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

Subversion Repositories klc32

[/] [klc32/] [trunk/] [rtl/] [verilog/] [overflow.v] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 robfinch
//=============================================================================
2
//      overflow.v
3
//      - compute overflow result for add/subtract
4
//
5
//
6
//      2005-2010  Robert Finch
7
//      rob@birdcomputer.ca
8
//
9
//
10
//
11
//      Verilog 1995
12
//
13
//      This source code is free for use and distribution for non-commercial or
14
//      evaluation purposes, provided this copyright statement and disclaimer
15
//      remains present in the file.
16
//
17
//      NO WARRANTY.
18
//      THIS Work, IS PROVIDEDED "AS IS" WITH NO WARRANTIES OF ANY KIND, WHETHER
19
//      EXPRESS OR IMPLIED. The user must assume the entire risk of using the
20
//      Work.
21
//
22
//      IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
23
//      INCIDENTAL, CONSEQUENTIAL, OR PUNITIVE DAMAGES WHATSOEVER RELATING TO
24
//      THE USE OF THIS WORK, OR YOUR RELATIONSHIP WITH THE AUTHOR.
25
//
26
//      IN ADDITION, IN NO EVENT DOES THE AUTHOR AUTHORIZE YOU TO USE THE WORK
27
//      IN APPLICATIONS OR SYSTEMS WHERE THE WORK'S FAILURE TO PERFORM CAN
28
//      REASONABLY BE EXPECTED TO RESULT IN A SIGNIFICANT PHYSICAL INJURY, OR IN
29
//      LOSS OF LIFE. ANY SUCH USE BY YOU IS ENTIRELY AT YOUR OWN RISK, AND YOU
30
//      AGREE TO HOLD THE AUTHOR AND CONTRIBUTORS HARMLESS FROM ANY CLAIMS OR
31
//      LOSSES RELATING TO SUCH UNAUTHORIZED USE.
32
//
33
//      
34
//      This module computes overflow for add/subtract given two operands and the
35
//      result. Assuming we don't know what the carry input is and there may
36
//      have been one.
37
//=============================================================================
38
 
39
module overflow(op, a, b, s, v);
40
 
41
        input op;       // 0=add,1=sub
42
        input a;
43
        input b;
44
        input s;        // sum
45
        output v;
46
 
47
        // Overflow:
48
        // Add: the signs of the inputs are the same, and the sign of the
49
        // sum is different
50
        // Sub: the signs of the inputs are different, and the sign of
51
        // the sum is the same as B
52
        assign v = (op ^ s ^ b) & (~op ^ a ^ b);
53
 
54
endmodule

powered by: WebSVN 2.1.0

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