Inline assembler calls a subroutine

I have a question about inline assembler. Is it possible to call another assembler routine from the inline assembler within the same function? For example:

void FindValidPID(unsigned int &Pid) { __asm { sub esp, 20h mov eax, Pid add eax,eax call sub123 ; another assm subroutine mov Pid, eax add esp, 20h } } 

Where should I and how to write a sub123 routine?

Cheers
Thomas

+6
c ++ assembly inline-assembly
source share
4 answers

If you are writing an entire subroutine in an assembly, you should study using file-level assembler rather than built-in.

+2
source share

Suppose you have a _func2 subroutine written in assembly language (I only know NASM syntax).

  global _func2 section .text _func2: ret 

You can call this routine from your C ++ code, for example,

 extern "C" { void func2(); } void func1() { __asm { call func2 } } int main() { func1(); } 

Of course, func2 can also be a C / C ++ function with a __asm block.

+1
source share

From the syntax, I assume that the compiler used is VC ++? If so, the bare function ( http://msdn.microsoft.com/en-us/library/5ekezyy2(VS.80).aspx ) should allow you to define a function that can be easily called from assembly language code.

(Naked functions are also visible in C ++, so you can also call them from C ++ and potentially get the wrong results ... so you just need to be careful!)

+1
source share

You could do this by creating another function in the same way as you did with 1st, and then call it your distorted name, for example call __GLOBAL__I_sub123; .

It might be a good idea to declare it extern "C" to make things easier.

In gcc, you can use gcc -S file.cpp to find out what the distorted name funciton is.

0
source share

All Articles