I'm trying to get my head around printing doubles in assembly but I'm failing miserably. I'm getting segfault when calling my own function that I'm planning to use as a helper to print doubles for debugging purposes. I was following these printf
examples: https://www.csee.umbc.edu/portal/help/nasm/sample.shtml
My code currently looks like this:
section .data
formatStrf: db `The number is %f\n`,0
section .text
extern printf
printfcallfloat:
;Pass in RDI
PUSH RDI ;Preserve value of rdi
PUSH RAX ;Preserve value of RAX
PUSH RDI;The value we want to print
PUSH DWORD formatStrf
CALL printf ;Segfault
POP RAX;Pop the stack back (too lazy to manually change the RSP value)
POP RAX
POP RAX;Restore the RAX and RDI
POP RDI
RET
I'm passing the floating point value to the RDI
reg as follows:
MOVSD QWORD [RSP], XMM0 ;Copy to stack
MOV RDI, QWORD [RSP]
CALL printfcallfloat
EDIT: I'm running this on linux.