-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcall.cpp
More file actions
88 lines (84 loc) · 976 Bytes
/
call.cpp
File metadata and controls
88 lines (84 loc) · 976 Bytes
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
#include "insn.h"
#include <iostream>
static int *sp, stack[100], result;
static bool iserr;
clock_t st, ed;
extern void exec_asm();
void handler_nop()
{
return;
}
void handler_int0()
{
*sp++ = 0;
}
void handler_int1()
{
*sp++ = 1;
}
void handler_int2()
{
*sp++ = 2;
}
void handler_int3()
{
*sp++ = 3;
}
void handler_int4()
{
*sp++ = 4;
}
void handler_int5()
{
*sp++ = 5;
}
void handler_int6()
{
*sp++ = 6;
}
void handler_int7()
{
*sp++ = 7;
}
void handler_int8()
{
*sp++ = 8;
}
void handler_add()
{
sp[-2] += sp[-1];
sp--;
}
void handler_sub()
{
sp[-2] -= sp[-1];
sp--;
}
void handler_mul()
{
sp[-2] *= sp[-1];
sp--;
}
void handler_div()
{
sp[-2] /= sp[-1];
sp--;
}
void handler_ret()
{
result = sp[-1];
iserr = false;
return;
}
void exec()
{
sp = &stack[0];
st = clock();
exec_asm();
ed = clock();
}
int main(void)
{
exec();
std::cout << ed - st << std::endl;
}