0

Want to print floating-point value via printf in assembly

    segment .data
float_fmt   db  "%f", 0xa, 0
fp  dd  1.1

    segment .text
    global  main
    extern  printf
main:
    push    rbp
    mov rbp, rsp
    lea rdi, [float_fmt]
    movss   xmm0, [fp]
    mov eax, 1
    call    printf
    leave
    ret

I want to print single-precision floating-point number(dd, 4 bytes), however, printf prints 0.000000 Changing

fp dd 1.1 

to

fp dq 1.1 ; store double-precision floating-point(dq, 8 bytes)

and

movss xmm0, [fp]

to

movsd xmm0, [fp] ; move double-precision floating-point (8 bytes)

solves the problem. Could you explain why?

Bulat M.
  • 680
  • 9
  • 25

0 Answers0