简体   繁体   中英

Call C function from asm file by passing function address in a register

I have a function named system_handler which is defined in a func.c . I need to call system_handler from another assembly program by passing the address of the function to a register and call the register.

So far I have written this:

       .extern system_handler   ; Is defined in func.c
       mov system_handler, %eax
       call %eax   ; This call is making run time error in emulator 
                   ; fatal: Trying to execute code outside RAM or ROM at 0x8b1cec83

While assembling the asm file I am getting a warning:

Warning: indirect call without '*'

compiler and assembler used: i586-gnu-{gcc/as} , Using AT&T format in asm file.

In AT&T syntax you should use mov $system_handler, %eax to load the address, what you did was loading the first dword of your function from memory.

To fix the warning, you should of course write call *%eax , which is another peculiarity of AT&T.

If you are not familiar with AT&T syntax, you can switch both gcc and gas to intel syntax.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM