Repository navigation
Expand file tree
/
Copy pathCPU.h
More file actions
124 lines (118 loc) · 2.66 KB
/
Copy pathCPU.h
File metadata and controls
124 lines (118 loc) · 2.66 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
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
#ifndef CPU_H_INCLUDED
#define CPU_H_INCLUDED
#include <iostream>
#include <vector>
#include <string>
#include "Memory.h"
//array of events set to 1 initially
static int eventState[10] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, };
enum Opcode {
INCR,
ADDI,
ADDR,
PUSHR,
PUSHI,
MOVI,
MOVR,
MOVMR,
MOVRM,
MOVMM,
PRINTR,
PRINTM,
PRINTCR,
PRINTCM,
JMP,
JMPI,
JMPA,
CMPI,
CMPR,
JLT,
JLTI,
JLTA,
JGT,
JGTI,
JGTA,
JE,
JEI,
JEA,
CALL,
CALLM,
RET,
EXIT,
POPR,
POPM,
SLEEP,
INPUT,
INPUTC,
SETPRIORITY,
SETPRIORITYI
};
class CPU
{
private:
std::vector<int> registers;
int* registerd[16];
int pointer;
int current_process_Id;
int stack_pointer;
int clock_tick;
int instruction_pointer;
int global_memory_start;
bool sign_flag;
bool zero_flag;
Memory* memory;
public:
CPU();
~CPU();
void perform_instructions(std::string& opcodestr, int operand1, int operand2);
void executeINCR(int reg_num);
void executeADDI(int reg_num, int constant);
void executeADDR(int reg_num, int reg_num1);
void pushRegister(int reg_num);
void pushConstant(int constant);
void executeMOVI(int reg_num, int constant);
void executeMOVR(int reg_num1, int reg_num2);
void executeMOVMR(int reg_num1, int reg_num2);
void executeMOVRM(int reg_num1, int reg_num2);
void executeMOVMM(int reg_num1, int reg_num2);
void executePRINTR(int reg_num);
void executePRINTM(int reg_num);
void executePRINTCR(int reg_num);
void executePRINTCM(int address);
void executeJMP(int address);
void executeJMPI(int offset);
void executeJMPA(int address);
void executeCMPI(int reg_num, int constant);
void executeCMPR(int reg_num1, int reg_num2);
void executeJLT(int reg_num);
void executeJLTI(int reg_num);
void executeJLTA(int reg_num);
void executeJGT(int offset);
void executeJGTI(int offset);
void executeJGTA(int address);
void executeJE(int offset);
void executeJEI(int offset);
void executeJEA(int address);
void executeCALL(int offset);
void executeCALLM(int offset);
void executeRET();
void executeEXIT();
void executePOPR(int reg_num);
void executePOPM(int reg_num);
void executeSLEEP(int cycles);
void executeINPUT(int reg_num);
void executeINPUTC(int reg_num);
void executeSETPRIORITY(int reg_num);
void executeSETPRIORITYI(int reg_num);
void MapSharedMem(int rx, int ry);
void AcquireLock(int lockNumber);
void ReleaseLock(int lockNumber);
void WaitEvent(int param);
void SignalEvent(int param);
void flags(int result);
void read_file();
void Alloc(int rx, int ry);
void FreeMemory(int rx);
void connectMemory(Memory& mem);
};
#endif // CPU_H_INCLUDED