[英]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.