Try to pass argument to C function in Nasm elf64 but it return SIGFPE error

Viewed 36

I try to implement the C sqrt function in Nasm elf64, it works correctly without argument (with the value of "a" define in the function), but when I try to pass an argument to this function ,the code return an error "Stopped reason: SIGFPE".

Here's my code

The c function

int le_sqrt(int a) {
   int n=1;
   int number = a;
   for (int i=0; i<10; i++) {
       n=(n+number/n)/2;  
   }
   return n; 
}

The nasm program

bits 64
global _start
extern le_sqrt 

_start:
    mov rbp,9 ;argument 
    push rbp ;same argument push
    call le_sqrt ; my c function

    mov rax,60 ;exit program
    mov rsi,0
    syscall
2 Answers

If you want to call le_sqrt(9) with System V AMD64 ABI calling convention, do this:

_start:
    mov rdi,9
    call le_sqrt
Related