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?

  • Is this about reverse engineering or about software engineering?
    – julian
    Aug 5, 2018 at 12:35
  • In fact i have reversed a program which contains that and i am wondering if it is possible to do that in c
    – Bob5421
    Aug 5, 2018 at 14:50
  • 1
    (1) This is not clear enough. It depends a lot on the compiler, optimization level, and whether you're willing to use __asm__. (2) It seems that you're having an XY problem. What are you trying to do?
    – user202729
    Aug 6, 2018 at 9:19
  • You want specifically ecx or any register that may do the job?
    – perror
    Aug 8, 2018 at 10:52
  • Spécificaly ecx
    – Bob5421
    Aug 8, 2018 at 13:31

1 Answer 1


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 */

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.