-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvm.h
70 lines (63 loc) · 807 Bytes
/
vm.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
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
#ifndef __VM_H__
#define __VM_H__
#include "vm_types.h"
// Register.
typedef enum _Register_Names {
A = 1,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
IP,
SP,
FLAGS,
} Register_Names;
typedef union _Register {
struct {
uint16_t ah : 16;
uint16_t al : 16;
uint16_t bh : 16;
uint16_t bl : 16;
} chunks;
vm_int_t data;
} Register;
// OPCodes.
typedef enum _OPCode_Names {
NOP,
MOV,
ADD,
SUB,
MUL,
DIV,
JZ,
JNZ,
JE,
JNE,
JLT,
JGT,
JMP,
PUSH,
POP,
OUT,
HALT,
} OPCode_Names;
// The VM.
typedef struct _VM {
vm_int_t *stack;
Register *registers;
vm_int_t *current_program;
} VM;
// Create and destroy.
VM *create_VM();
void destroy_VM();
// Set attributes.
int load_VM_Program(VM*, const vm_int_t*);
void run_VM(VM*);
#endif