-
Notifications
You must be signed in to change notification settings - Fork 0
/
alu.v
98 lines (68 loc) · 1.8 KB
/
alu.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
module Sixty_Four_bit_adder(num1,num2,sum,control,overflow);
input [63:0] num1,num2;
input control;
output [63:0] sum;
wire [63:0] carry;
output overflow;
wire [63:0] w1,w2,w3,num2_change;
genvar i;
generate
for (i = 0; i < 64; i = i + 1)
begin
xor x1(num2_change[i],num2[i],control); // xor of b
xor x2(w1[i],num1[i],num2_change[i]);//xor of a and b'
xor x3(sum[i],w1[i],i==0?control:carry[i-1]);//final sum using cin and second line
and a1(w2[i],i==0?control:carry[i-1],w1[i]);
and a2(w3[i],num1[i],num2_change[i]);
or o1(carry[i],w2[i],w3[i]);
end
endgenerate
assign overflow = carry[63]^sum[63];
endmodule
module ander_block(num1,num2,bit_wise_and);
input [63:0] num1, num2;
output [63:0] bit_wise_and;
genvar i;
generate
for (i = 0; i < 64; i = i + 1)
begin
and a(bit_wise_and[i],num1[i],num2[i]);
end
endgenerate
endmodule
module xor_block(num1,num2,bit_wise_xor);
input [63:0] num1, num2;
input control;
output [63:0] bit_wise_xor,final;
genvar i;
generate
for (i = 0; i < 64; i = i + 1)
begin
xor a(bit_wise_xor[i],num1[i],num2[i]);
end
endgenerate
endmodule
module final(num1,num2,control,overflow,out);
input [63:0] num1,num2;
input [1:0] control;
wire [63:0] add_sub,bitwise_and,bitwise_xor;
output overflow;
reg [63:0] FINAL;
output[63:0] out;
Sixty_Four_bit_adder ADDER(num1,num2,add_sub,control[0],overflow);
ander_block ANDER(num1,num2,bitwise_and);
xor_block XOR(num1,num2,bitwise_xor);
always @*
case (control)
2'b00 , 2'b01: begin
FINAL = add_sub;
end
2'b10: begin
FINAL = bitwise_and;
end
2'b11:begin
FINAL = bitwise_xor;
end
endcase
assign out = FINAL;
endmodule