-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexecute.h
42 lines (38 loc) · 857 Bytes
/
execute.h
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
#ifndef EXECUTE_H
#define EXECUTE_H
#include "mem.h"
bool alu_zero = false;
int branch_target = 0;
int execute(int readData1, int readData2, int alu_op) {
alu_zero = false;
switch(alu_op) {
case 0:
// 0000 do AND
return (readData1 & readData2);
case 1:
// 0001 do OR
return (readData1 | readData2);
case 2:
// 0010 do add
return (readData1 + readData2);
case 6:
// 0110 substract
if(readData1 - readData2 == 0) {
alu_zero = true;
}
return (readData1 - readData2);
case 7:
// 0111 do set-on-less-than
if (readData1 < readData2){
return 1;
}
return 0;
case 0xc:
// 1100 do NOR
return (~(readData1 | readData2));
default:
return 0;
}
return 0;
}
#endif