I have a C program linked into my NASM program to call printf. The C progam has two functions, one to print integer values and the other to print float values:
int Test_Print_2(int64_t value_passed_in)
{
printf ("value: %lu\n", value_passed_in);
return 0;
}
int Test_Print_2F(double value_passed_in)
{
printf ("Inside Test_Print - Float ");
printf ("q[0]: %f\n", value_passed_in);
//printf ("q[0]: %4.4lf\n", value_passed_in);
return 0;
}
The first program (Test_Print_2) works with no problem, but the second program (Test_Print_2F) throws a segfault. It doesn’t even print the line "Inside Test_Print - Float " If I comment out the print line then it does print the line "Inside Test_Print - Float " – so something is wrong with my format for printing doubles.
To print as integer, I call it from NASM like this:
movsd xmm0,[rdi] ; the values in the array pointed to by rdi are doubles
cvttsd2si rax,xmm0 ; convert to integer
%include "/opt/P01_SH/_Include_Utilities/ABI_Stack_Push.asm"
mov rdi,rax
call [rel Test_Print_2 wrt ..got]
%include "/opt/P01_SH/_Include_Utilities/ABI_Stack_Pop.asm"
That works and prints just the integer part of the floating point number. However, when I call it from NASM to print as a double like this:
movsd xmm0,[rdi]
%include "/opt/P01_SH/_Include_Utilities/ABI_Stack_Push.asm"
mov rax,1
call [rel Test_Print_2F wrt ..got]
%include "/opt/P01_SH/_Include_Utilities/ABI_Stack_Pop.asm"
it segfaults without printing anything. Both programs are linked in from the object file (I often link C object files into NASM).
Thanks for any help on this.