[英]Call C function from asm file by passing function address in a register
我有一个名为system_handler
的函数,该函数在func.c
定义。 我需要通过将函数的地址传递给寄存器并调用该寄存器,从另一个汇编程序调用system_handler
。
到目前为止,我已经写了这个:
.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
组装asm文件时,我收到警告:
Warning: indirect call without '*'
使用的编译器和汇编器: i586-gnu-{gcc/as}
,在asm文件中使用AT&T格式。
在AT&T语法中,应使用mov $system_handler, %eax
加载地址,所做的就是从内存中加载函数的第一个dword。
要解决该警告,您当然应该编写call *%eax
,这是AT&T的另一个特点。
如果您不熟悉AT&T语法,则可以将gcc
和gas
都切换为intel语法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.