-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
46 lines (35 loc) · 1.01 KB
/
main.cpp
File metadata and controls
46 lines (35 loc) · 1.01 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
#include <iostream>
#include "header/State.h"
#include "header/InstructionSet.h"
#include "header/Logger.h"
using namespace vm2;
void usage(){
std::cout << "Usage: vm2 [file]" << std::endl;
}
int main(int argc, char** argv) {
if(argc < 2){
usage();
return -1;
}
State* state = new State(argv[1]);
InstructionSet* instructionSet = new InstructionSet();
for(size_t i = 2; i < argc; i++){
int num = std::stoi(argv[i]);
uint32_t value = *(uint32_t*)#
value &= 0x7FFF;
if(num < 0)
value |= 1 << 31;
state->getStack()->push(value, 0x00);
}
state->getStack()->push((uint32_t)argc - 2, 0x00);
while (state->readIp() != 0x11){
char opcode[5] = {0};
sprintf(opcode, "%#04x", state->readIp());
Logger::get().log("[INSTRUCTION] " + std::string(opcode));
instructionSet->get(state->readIp())->call(state);
}
std::cout << std::endl;
delete state;
delete instructionSet;
return 0;
}