I'm attempting to create a square root function with my double sqrt(double num)
where num is the number that will be square rooted. Let's say I input a 25.25 into my function. The expected output will be 5.02493781056
according to my calculator. However, somehow is getting a segmentation fault. The function is purely for learning purposes. I was browsing on the internet saying that I need to return the full value of the memory address that I'm returning. Here is what I have. The code snippet is running with nasm -f macho64
with a main.c
file.
sqrt.s
section .text
global _sqrt
; double sqrt(double num);
_sqrt:
fld qword [rdi] ; read the number given
fsqrt ; float square root instruction
fst qword [rax] ; float store value to rax
ret ; and return it's value
main.c
int main(void)
{
printf("my square function return: %f", sqrt(25));
return (0);
}