I want to generate this assembly code:
mov ecx, <absolute address of func1>
call ecx
How can I write and compile C code which generates this code?
Usually the compiler will generate the call using the address of the function directly. But since in your case it uses a register, it reminds me of C++ vtables. So in C, how about calling a pointer to a function? Something like this:
void (*fptr)(void);
void foo(void) {
/* some code */
}
fptr = foo;
(*fptr)(); /* <-- your indirect call generated here */
__asm__
. (2) It seems that you're having an XY problem. What are you trying to do?ecx
or any register that may do the job?