Calling inline assembly directly
Posted on 2003-10-30
Basically, I need a way to get the memory address of the first instruction in an __asm block. Here's an example of what I'm talking about:
mov eax, 1
add eax, 2
printf("This never gets executed because the asm block jumps back to where it was called from");
Basically, at runtime I'm going to change the instruction at MEMADDRESS-1 to jmp to the first statement, "mov eax, 1"(obviously just a placeholder for now). The rest of the asm block runs, then jmps back to MEMADDRESS and the program will proceed as normal.
The only problem is I need to find the address of that first instruction in order to make the jmp to it. I don't want to call ThisFunctionNeverGetsCalledDirectly() because __asm modifies all the registers, the stack pointer,etc. The point is I want the assembly code to execute seamlessly as though it actually existed between MEMADDRESS-1 and MEMADDRESS.
Thanks for the help.