How to pass a string as an argument to a call command in an inline assembly?

Essentially, I would like to do something like this:

//assume myFunction is defined and takes one argument that is an int
char * functionName = "myFunction";
int arg = 5;

__asm{
    push a
    call functionName
}

Basically, I want to call a function whose name is stored in a string. What would be the correct syntax for this?

Edit: We are talking about x86 assembly

+3
source share
4 answers

You cannot, at least not directly.

. "call functionName", . . , C ++ - , . DLL, GetProcAddress, .

, .

- :

std:map<string, PVOID> functionMappings;
functionMappings["MyFunction"] = MyFunction;


// Later


PVOID function = functionMappings["MyFunction"];

__asm
{
    push a;
    call [function]
}

:

, , , PVOID. Windows x86/x64.

, - stdcall.

, , - ?

+1

, . , - . , , - . , C ++ , , .

: , , , , . , ..

+1

: , , , , .

: , , - , (, ). , functionName . , : .

( , , -, , , , ... .)

0

, . , C, . . , , , , , .

Or you could use the function pointers defined at compile time to store the addresses of the functions you are interested in (although you still need to somehow translate the string into a function pointer, presumably by looking up the string comparison table), if that’s what you interested, I would suggest writing the C equivalent, and then look at the assembly code that the compiler gives out to see how it handles function pointers.

0
source

Source: https://habr.com/ru/post/1733394/


All Articles