-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathalu.v
More file actions
71 lines (68 loc) · 1.79 KB
/
Copy pathalu.v
File metadata and controls
71 lines (68 loc) · 1.79 KB
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
module alu(
input [31:0] A,B, // ALU 8-bit Inputs
input [3:0] ALU_Sel,// ALU Selection
input rst,
output [63:0] ALU_Out, // ALU 8-bit Output
output [3:0] NZCV_out
);
reg [63:0] ALU_Result;
reg [3:0] nzcv; // Carryout flag
assign ALU_Out = ALU_Result; // ALU out
assign NZCV_out = nzcv;
always @(*)
begin
case(ALU_Sel)
4'b0000: // Logical and
ALU_Result = A & B ;
4'b0001: // xor
ALU_Result = A ^ B ;
4'b0010: //
ALU_Result = A - B;
4'b0011: //
ALU_Result = B - A;
4'b0100: //
ALU_Result = A+B;
4'b0101: //
ALU_Result = A+B+nzcv[1];
4'b0110: // SBC
ALU_Result = A-B-~(nzcv[1]);
4'b0111: // RSC
ALU_Result = B-A-~(nzcv[1]);
4'b1000: // TST
ALU_Result = A & B;
4'b1001: // TESTEQ
ALU_Result = A ^ B;
4'b1010: // Compare
ALU_Result = A - B;
4'b1011: // Compare Negative
ALU_Result = A + B;
4'b1100: // Logical OR
ALU_Result = A | B;
4'b1101: // MOV
ALU_Result = B;
4'b1110: // BitClear
ALU_Result = A & ~(B);
4'b1111: // REVMOV
ALU_Result = A;
default: ALU_Result = A + B ;
endcase
if(rst) begin
nzcv = 4'b0000;
end
else begin
nzcv[3] = ALU_Result[31];
if(ALU_Result == 32'h0000)
nzcv[2] = 1;
else
nzcv[2] = 0;
if(A > 0 && B > 0 && ALU_Result>>31 != 0)
nzcv[0] = 1;
else
nzcv[0] = 0;
if(ALU_Result >> 32 != 0)
nzcv[1] = 1;
else
nzcv[0] = 0;
end
end
endmodule