Skip to content

Instantly share code, notes, and snippets.

@0xF6
Created February 10, 2021 22:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0xF6/7d871bd4bcaa7c9b62bef0d1bf9ae071 to your computer and use it in GitHub Desktop.
Save 0xF6/7d871bd4bcaa7c9b62bef0d1bf9ae071 to your computer and use it in GitHub Desktop.
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