0

I am trying to understand how to declare and use function pointers in assembly. In this example I want call_add to call add_fnct. Which may be passed as a pointer. However when CALL [rdx] is executed, it results in an segmentation fault.

 MOV rdx, add_fnct
    CALL call_add
    ret
    
add_fnct:
    ADD rdi,rsi
    MOV rax,rdi
    RET  
    
call_add:
    MOV rdi, 5
    MOV rsi, 6
    CALL [rdx]
    RET 
HeapUnderStop
  • 378
  • 1
  • 9
  • 4
    RDX is a function pointer, not a pointer to a function-pointer. Use `call rdx` to do `RIP=RDX`, not `RIP=mem[rdx]`. Your code doesn't include any "declaration" of a function pointer so IDK what you mean by that part of the title question. A function pointer is just a 64-bit integer that happens to be the address of some machine code, like usual in asm. Often you'll get that address as the address of a symbol. – Peter Cordes May 09 '23 at 18:10

0 Answers0