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

Subversion Repositories ecpu_alu

[/] [ecpu_alu/] [trunk/] [adder/] [alu_adder.v] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 leonous
 
2
// ported from university project for an ALU in VHDL
3
module alu_adder  (
4
                    x          ,
5
                    y          ,
6
                    carry_in   ,
7
                    ORsel      ,
8
                    XORsel     ,
9
 
10
                    carry_out  ,
11
                    xor_result ,
12
                    or_result  ,
13
                    and_result ,
14
                    z
15
                  );
16
 
17
  parameter ADDER_WIDTH = 8;
18
 
19
  input       [ADDER_WIDTH - 1 :0] x          ;
20
  input       [ADDER_WIDTH - 1 :0] y          ;
21
  input                            carry_in   ;
22
  input                            ORsel      ;
23
  input                            XORsel     ;
24
 
25
  output      [ADDER_WIDTH - 1 :0] xor_result ;
26
  output      [ADDER_WIDTH - 1 :0] or_result  ;
27
  output      [ADDER_WIDTH - 1 :0] and_result ;
28
  output      [ADDER_WIDTH     :0] carry_out  ;
29
  output      [ADDER_WIDTH - 1 :0] z          ;
30
 
31
  reg         [ADDER_WIDTH     :0] carry_out  ;
32
  reg         [ADDER_WIDTH - 1 :0] z          ;
33
 
34
  wire        [ADDER_WIDTH - 1 :0] XxorY      ;
35
  wire        [ADDER_WIDTH - 1 :0] XandY      ;
36
  wire        [ADDER_WIDTH - 1 :0] XorY       ;
37
 
38
  // loop variable register
39
  reg   [31:0] i;
40
 
41
        ////////////////////////////////////////////////////
42
  // adder
43
  ////////////////////////////////////////////////////
44
  assign  xor_result    = XxorY   ;
45
  assign  or_result       = XorY    ;
46
  assign  and_result    = XandY   ;
47
 
48
        assign  XxorY         = x ^ y   ;
49
        assign  XandY         = x & y   ;
50
        assign  XorY          = x | y   ;
51
 
52
 
53
  //  adder
54
  always  @(x or y or carry_out or XxorY or XandY or XorY or XORsel or ORsel)
55
  begin
56
    carry_out[0] <= carry_in;
57
    for (i = 0; i < ADDER_WIDTH ; i = i+1)
58
    begin
59
        z[i]            <=  XxorY[i] ^ ( carry_out[i] & XORsel);
60
        carry_out[i+1]  <=  XandY[i] | ((carry_out[i] | ORsel) & XorY[i]);
61
    end
62
  end
63
 
64
 
65
endmodule
66
 
67
 

powered by: WebSVN 2.1.0

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