* 在指令操作数前面,GNU 汇编,AMD64
* in front of instruction operand, GNU assembly, AMD64
我一直在努力学习为 AMD64 处理器编写汇编代码。我一直在查看 gcc 生成的代码。最终,我开始看到诸如
之类的说明
call *(%rax)
操作数前面的*是做什么用的?我正在阅读的 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 [=11=], %eax
jl .Ldefault
// Jump to the default case if the control variable is
// greater than 2.
cmp , %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
在 AT&T 语法中,间接跳转或函数调用的操作数带有星号前缀 *
,以区别于直接跳转或函数调用。这样做的目的是为了区分对函数的调用和对存储在变量中的函数指针的间接调用:
call function
call *function_pointer
我一直在努力学习为 AMD64 处理器编写汇编代码。我一直在查看 gcc 生成的代码。最终,我开始看到诸如
之类的说明 call *(%rax)
操作数前面的*是做什么用的?我正在阅读的 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 [=11=], %eax
jl .Ldefault
// Jump to the default case if the control variable is
// greater than 2.
cmp , %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
在 AT&T 语法中,间接跳转或函数调用的操作数带有星号前缀 *
,以区别于直接跳转或函数调用。这样做的目的是为了区分对函数的调用和对存储在变量中的函数指针的间接调用:
call function
call *function_pointer