Created
February 10, 2021 22:07
-
-
Save 0xF6/7d871bd4bcaa7c9b62bef0d1bf9ae071 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum | |
{ | |
NOP, | |
ADD | |
}; | |
struct thestack { | |
union { | |
int i; | |
} data; | |
int type; | |
}; | |
enum | |
{ | |
TYPE_INT | |
}; | |
void xuy(thestack* args, short* code, int code_size) | |
{ | |
auto* const stack = static_cast<thestack*>(calloc(64, sizeof(thestack))); | |
register auto* sp = stack; | |
register auto* ip = code; | |
auto* end = ip + code_size; | |
while (1) | |
{ | |
if(*ip == *end) | |
printf("the fucking end"); | |
switch(*ip) | |
{ | |
case NOP: | |
printf("nop"); | |
++ip; | |
break; | |
case ADD: | |
ip++; | |
sp--; | |
if (sp->type == TYPE_INT) | |
{ | |
sp[-1].data.i += sp[0].data.i; | |
} | |
break; | |
} | |
} | |
} | |
void call() | |
{ | |
short code[] = { | |
0x0, | |
0x1 | |
}; | |
auto* const args = new thestack[2]; | |
args[0].type = TYPE_INT; | |
args[0].data.i = 15; | |
args[1].type = TYPE_INT; | |
args[1].data.i = 10; | |
xuy(args, code, 2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment