Unc*_*ome 0 assembly gnu x86-64
我一直在努力学习为 AMD64 处理器编写汇编代码。我一直在看 gcc 生成的代码。最终,我开始看到诸如
call *(%rax)
Run Code Online (Sandbox Code Playgroud)
操作数前面的 * 是做什么的?我正在阅读的 System V ABI 文档中出现了类似的内容,上述问题的答案将帮助我继续。以下是上下文中使用的语法示例,取自 System V ABI 文档本身:
// System V ABI suggested implementation of a
// C switch statement with case labels 0, 1, and 2,
// and a default label.
// Jump to the default case if the control variable is
// less than 0.
cmpl $0, %eax
jl .Ldefault
// Jump to the default case if the control variable is
// greater than 2.
cmp $2, %eax
jg .Ldefault
movabs $.Ltable, %r11
jmpq *(%r11,%eax,8) /* Here is that syntax. */
.section .lrodata,"aLM",@progbits,8
.align 8
.Ltable: .quad .Lcase0
.quad .Ldefault
.quad .Lcase2
.quad .previous
.Ldefault:
// Code for default case
.Lcase0:
// Code for case 0
.Lcase1:
// Code for case 1
.Lcase2:
// Code for case 2
Run Code Online (Sandbox Code Playgroud)
在 AT&T 语法中,间接跳转或函数调用的操作数以星号*为前缀,以区别于直接跳转或函数调用。这样做的目的是区分对函数的调用和对存储在变量中的函数指针的间接调用:
call function
call *function_pointer
Run Code Online (Sandbox Code Playgroud)