-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalu.luc
71 lines (64 loc) · 1.45 KB
/
alu.luc
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 a[16],
input b[16],
input alufn_signal[6],
output out[16],
output z,
output v,
output n
) {
adder adder;
boolean boolean;
shifter shifter;
compare compare;
multiplier multiplier;
always {
shifter.alufn_signal = 0;
compare.z = 0;
compare.v = 0;
compare.n = 0;
compare.alufn_signal = 0;
multiplier.a = a;
multiplier.b = b;
// YOUR ANSWER HERE // alu.luc body
adder.a = a;
adder.b = b;
adder.alufn_signal = alufn_signal;
z = adder.z;
v = adder.v;
n = adder.n;
out = adder.out;
compare.z = adder.z;
compare.v = adder.v;
compare.n = adder.n;
compare.alufn_signal = alufn_signal;
out = compare.cmp;
boolean.a = a;
boolean.b = b;
boolean.alufn_signal = alufn_signal;
out = boolean.bool;
shifter.a = a;
shifter.b = b[4:0];
shifter.alufn_signal = alufn_signal;
out = shifter.shift;
case(alufn_signal[5:4]){
b00:
case(alufn_signal[1]){
b0:
out = adder.out;
b1:
out = multiplier.mul;
}
b01:
out = boolean.bool;
b10:
out = shifter.shift;
b11:
out = compare.cmp;
default:
out = 16b0;
}
if (alufn_signal == 6b010101){
out = ^a; // custom functionality, reduction xor
}
}