警告:没有‘*’的间接调用 [英] Warning: indirect call without `*'
问题描述
有这个简单的组装:
.text
.globl main
str:
.asciz "%i\n"
add:
push %rbp
mov %rsp, %rbp
movl %esi, %eax
addl %edi, %eax
pop %rbp
ret
main:
mov $1, %esi
mov $2, %edi
lea add(%rip), %rax
call %rax #what is wrong here? the rax should contain first instruction of add
mov %eax, %esi
xor %eax, %eax
lea str(%rip), %rdi
call printf
xor %eax, %eax
ret
我收到错误:
foo.s:17: Warning: indirect call without `*'
为什么?%rax
应该包含函数的地址(如注释中所示),而不是 c
,那里有带有 *
的指针,但注册包含地址.那么这里出了什么问题?
Why? The %rax
should contain the address of function (as denoted in comment), and this is not c
, where there are pointer with *
, but register that contains an address. So what is wrong here?
推荐答案
更改
call %rax
到
call *%rax
这与call *(%rax)
不同.来自@interjay 的评论如下:
This is not the same as call *(%rax)
. From @interjay's comment below:
call *%rax
调用存储在 rax
中的地址(这是 OP 想要做的),而 call *(%rax)
调用rax
call *%rax
calls the address stored inrax
(which is what OP wants to do), whilecall *(%rax)
calls the address stored in memory pointed to byrax
星号表示调用是间接调用.这意味着调用存储在 %rax
The asterisk indicates that the call is an indirect call. It means call function stored inside %rax
这篇关于警告:没有‘*’的间接调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!