什么 c 代码会编译为类似 `call *%eax` 的代码?

hma*_*tt1 5 c assembly

我正在使用 c 和程序集,我call *%eax在几个地方看到过。我想编写一个小的 c 程序来编译成这样的东西,但我被卡住了。

我正在考虑像在这个问题中那样编写一些汇编代码:x86 汇编指令:在我的情况下仅使用 AT&T 语法调用 *Reg以获得一个带有调用的小示例。但是,这并不能解决我的紧迫问题,即什么样的 c 代码会编译成那样?

我知道这是对 eax 指向的地址的调用。

Ani*_*nge 3

文档:http://gcc.gnu.org/onlinedocs/gcc/Local-Reg-Vars.html#Local-Reg-Vars

尝试这个

#include <stdio.h>

typedef void (*FuncPtr)(void);
void _Func(void){
   printf("Hello");
}

int main(int argc, char *argv[]){
   register FuncPtr func asm ("eax") = _Func;
   func();

   return 0;
}   
Run Code Online (Sandbox Code Playgroud)

及其相关组装:

    .file   "functorTest.c"
    .section .rdata,"dr"
LC0:
    .ascii "Hello\0"
    .text
.globl __Func
    .def    __Func; .scl    2;  .type   32; .endef
__Func:
    pushl   %ebp
    movl    %esp, %ebp
    subl    $24, %esp
    movl    $LC0, (%esp)
    call    _printf
    leave
    ret
    .def    ___main;    .scl    2;  .type   32; .endef
.globl _main
    .def    _main;  .scl    2;  .type   32; .endef
_main:
    pushl   %ebp
    movl    %esp, %ebp
    andl    $-16, %esp
    call    ___main
    movl    $__Func, %eax
    call    *%eax       ; see? 
    movl    $0, %eax
    movl    %ebp, %esp
    popl    %ebp
    ret
    .def    _printf;    .scl    2;  .type   32; .endef
Run Code Online (Sandbox Code Playgroud)