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

Subversion Repositories blue

[/] [blue/] [trunk/] [blue8/] [alu.v] - Blame information for rev 4

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

Line No. Rev Author Line
1 2 wd5gnr
/*
2
    This file is part of Blue8.
3
 
4
    Foobar is free software: you can redistribute it and/or modify
5
    it under the terms of the GNU Lesser General Public License as published by
6
    the Free Software Foundation, either version 3 of the License, or
7
    (at your option) any later version.
8
 
9
    Foobar is distributed in the hope that it will be useful,
10
    but WITHOUT ANY WARRANTY; without even the implied warranty of
11
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
    GNU Lesser General Public License for more details.
13
 
14
    You should have received a copy of the GNU Lesser General Public License
15
    along with Blue8.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
    Blue8 by Al Williams alw@al-williams.com
18
 
19
*/
20
 
21
`default_nettype none
22
module alu(input wire [15:0] y,input wire [15:0] z,output reg [15:0] dout,
23
  input wire asum,input wire aor,input wire aand,input wire axor,input wire abar,input wire a2, input wire adiff,
24
  input wire ahalf,
25
  output wire overflow, output wire zero, output reg cy,input wire cin);
26
   assign        overflow=asum&&(y[15]==z[15]?1'b1:1'b0)&&dout[15]!=y[15];
27
   assign    zero=(dout==0?1'b1:1'b0);
28
 
29
 
30
        // carry is a problem since we use the ALU to handle increment PC
31
        // we really need an sendinc line that increments with no carry or something
32
        // although address arith ought not overflow ;-)
33
        // or we need to latch it at the right time like we do Z
34
        // Even then, putting carry as a reg here gives a combinatorial clock
35
        // I'd like to pull it out as a flag, but I can't seem to figure how to do that
36
        // with an assignment (particularly in sum) and changing the ALU clock to clk does NOT work!
37
 
38
 
39
 
40
   always @(*) begin
41
 
42
     case ({ahalf,adiff, asum, aor, aand, axor, abar, a2})
43
      8'b00000001: begin          //a2
44
                    {cy, dout}<={z[15:0], cin};  // could use cy to rotate
45
                end
46
      8'b00000010: begin                        // abar
47
                   dout<=~z;
48
                                                 cy<=cin;
49
                end
50
      8'b00000100: begin                                         // axor
51
                                                 dout<=y^z;
52
                                                 cy<=cin;
53
                end
54
      8'b00001000: begin                                 // aand
55
                   dout<=y&z;
56
                                                 cy<=cin;
57
                end
58
      8'b00010000: begin                                          // aor
59
                   dout<=y|z;
60
                                                 cy<=cin;
61
                end
62
      8'b00100000: begin                                          // asum
63
                    {cy, dout}<=y+z;
64
                end
65
      8'b01000000: begin                                                        // adiff
66
                    {cy, dout}<={1'b1, z}-y;
67
                end                                                                                       // ahalf
68
      8'b10000000: begin
69
                                             { dout, cy}<={cin, z[15:0]};
70
                                         end
71
      default : begin
72
                                                 cy<=cin;
73
                   dout<=16'bz;
74
                end
75
   endcase
76
 
77
 
78
   end
79
 
80
endmodule // alu
81
 
82
 

powered by: WebSVN 2.1.0

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