-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalsu.v
193 lines (193 loc) · 4.69 KB
/
alsu.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
module ALSU (clk,rst,A,B,cin,serial_in,red_op_A,red_op_B,opcode,bypass_A,bypass_B,direction,leds,out);
parameter INPUT_PRIORITY="A";
parameter FULL_ADDER="ON";
input clk,rst,cin,serial_in,red_op_A,red_op_B,bypass_A,bypass_B,direction;
input [2:0] A,B,opcode;
output [15:0] leds;
output [5:0] out;
reg cin_ff,serial_in_ff,red_op_A_ff,red_op_B_ff,bypass_A_ff,bypass_B_ff,direction_ff;
reg [2:0] A_ff,B_ff,opcode_ff;
reg [15:0] leds_tmp;
reg [5:0] out_tmp;
//creating the DFFs for the inputs:
always @(posedge clk or posedge rst) begin
if(rst) begin
A_ff<=0;
end
else begin
A_ff<=A;
end
end
always @(posedge clk or posedge rst) begin
if(rst) begin
B_ff<=0;
end
else begin
B_ff<=B;
end
end
always @(posedge clk or posedge rst ) begin
if(rst) begin
opcode_ff<=0;
end
else begin
opcode_ff<=opcode;
end
end
always @(posedge clk or posedge rst) begin
if(rst) begin
cin_ff<=0;
end
else begin
cin_ff<=cin;
end
end
always @(posedge clk or posedge rst) begin
if(rst) begin
serial_in_ff<=0;
end
else begin
serial_in_ff<=serial_in;
end
end
always @(posedge clk or posedge rst) begin
if(rst) begin
red_op_A_ff<=0;
end
else begin
red_op_A_ff<=red_op_A;
end
end
always @(posedge clk or posedge rst) begin
if(rst) begin
red_op_B_ff<=0;
end
else begin
red_op_B_ff<=red_op_B;
end
end
always @(posedge clk or posedge rst) begin
if(rst) begin
bypass_A_ff<=0;
end
else begin
bypass_A_ff<=bypass_A;
end
end
always @(posedge clk or posedge rst) begin
if(rst) begin
bypass_B_ff<=0;
end
else begin
bypass_B_ff<=bypass_B;
end
end
always @(posedge clk or posedge rst) begin
if(rst) begin
direction_ff<=0;
end
else begin
direction_ff<=direction;
end
end
////////////////////////////////////////////////
always @(posedge clk or posedge rst) begin
if(rst)begin
out_tmp<=0;
leds_tmp<=0;
end
else if((bypass_A_ff&&!bypass_B_ff)||(bypass_A_ff&&(INPUT_PRIORITY=="A")))begin
out_tmp<=A_ff;
leds_tmp<=0;
end
else if((bypass_B_ff&&!bypass_A_ff)||(bypass_B_ff&&(INPUT_PRIORITY=="B")))begin
out_tmp<=B_ff;
leds_tmp<=0;
else if(((red_op_A_ff)&&(red_op_B_ff)&&(!{opcode_ff[2],opcode_ff[1]}))||(opcode_ff==3'b110)||(opcode_ff==3'b111)) begin
out_tmp<=0;
leds_tmp<=(~(leds_tmp));
end
end
else begin
casex ({opcode_ff,red_op_A_ff,red_op_B_ff})
5'b00000:begin
out_tmp<=A_ff&B_ff;
leds_tmp<=0;
end
5'b00010:begin
out_tmp<=&A_ff;
leds_tmp<=0;
end
5'b00001:begin
out_tmp<=&B_ff;
leds_tmp<=0;
end
5'b00011:begin
if(INPUT_PRIORITY=="A")begin
out_tmp<=&A_ff;
leds_tmp<=0;
end
else if(INPUT_PRIORITY=="B") begin
out_tmp<=&B_ff;
leds_tmp<=0;
end
end
5'b00100:begin
out_tmp<=A_ff^B_ff;
leds_tmp<=0;
end
5'b00110:begin
out_tmp<=^A_ff;
leds_tmp<=0;
end
5'b00101:begin
out_tmp<=^B_ff;
leds_tmp<=0;
end
5'b00111:begin
if(INPUT_PRIORITY=="A")begin
out_tmp<=^A_ff;
leds_tmp<=0;
end
else if(INPUT_PRIORITY=="B") begin
out_tmp<=^B_ff;
leds_tmp<=0;
end
end
5'b010xx:begin
if(FULL_ADDER=="ON") begin
out_tmp<=A_ff+B_ff+cin_ff;
end
else if (FULL_ADDER=="OFF") begin
out_tmp<=A_ff+B_ff;
end
leds_tmp<=0;
end
5'b011xx:begin
out_tmp<=A_ff*B_ff;
leds_tmp<=0;
end
5'b100xx:begin
if(direction_ff)begin
out_tmp<={out_tmp[4:0],serial_in_ff};
end
else begin
out_tmp<={serial_in_ff,out_tmp[5:1]};
end
leds_tmp<=0;
end
5'b101xx:begin
if(direction_ff)begin
out_tmp<={out_tmp[4:0],out_tmp[5]};
end
else begin
out_tmp<={out_tmp[0],out_tmp[5:1]};
end
leds_tmp<=0;
end
endcase
end
end
assign out=out_tmp;
assign leds=leds_tmp;
endmodule