Having this simple assembly:
.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
I am getting error:
foo.s:17: Warning: indirect call without `*'
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?
Change
call %rax
to
call *%rax
This is not the same as call *(%rax)
. From @interjay's comment below:
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
The asterisk indicates that the call is an indirect call. It means call function stored inside %rax