4

So I've been screwing around with the __asm block in VS2010 and I haven't been able to find a better way to get the pointer to the start of the assembly block.

The only way I know how to do this, is to declare a void function. One problem with this is that the void function will have its own assembly before and after my assembly block and I would have to compensate by getting the real address of the function and adding an offset.

Example:

c++

void myfunc(){
    __asm{
        nop
        nop
        nop
        ret
    }
}  

Would result in assembly similar to this:

push ebp
mov ebp,esp
add esp,8
nop
nop
nop
retn
mov esp,ebp
pop ebp
retn

myfunc() would most likely error if executed.

0

1 Answer 1

4

You basically want to enable __declspec(naked) on your function, to avoid the compiler-generated prologue and epilog.

See also: http://msdn.microsoft.com/en-us/library/h5w10wxs(v=vs.80).aspx

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.