I am trying to "embed" my virtual machine by copying code segments from C code between tags to memory allocated by malloc. So I have Ops defined using start and end labels, and I want to copy the instruction defined by the following code to the buffer and then execute (Im not sure if this is possible)
OP_PUSH0_START:
sp += 4; *sp = 0;
OP_PUSH0_END:
to do this, I thought the following code snippet would work
void * ptr0 = &&OP_PUSH0_START;
void * ptr1 = &&OP_PUSH0_END;
while(ptr0 < ptr1)
{
buf[c++] = *ptr0;
ptr0++;
}
goto buf;
but I can not read it without receiving a memory error
I would welcome any links or any suggestions on how to achieve this.
source
share