0

I would like to print a float number in x86 assembly using printf. Here is my code.

.data
number1: .float 18.0
format: .ascii "%f\n"
.text
.global main

main:

movsd liczba1, %xmm0
push %ebp
mov %esp, %ebp
#dont know to push %xmm0 on stack
push $format
call printf
mov %ebp, %esp
pop %ebp


mov $1, %eax
mov $0, %ebx
int $0x80

I guess that pushing %xmm0 registry on stack would make the whole thing work but I couldn't find solution how to do it.

dav1per
  • 15
  • 6
  • There is no instruction to do that. Instead, allocate space on the stack and use a `mov` instruction to store into memory. – fuz May 25 '22 at 18:56
  • 2
    Note that due to how C works, you need to convert to double. – Jester May 25 '22 at 18:57
  • [How to print a single-precision float with printf](https://stackoverflow.com/q/37082784) re: needing to convert to `double` for `%f`. Then yes, just make space on the stack and `movsd %xmm0, (%esp)` to push "manually". – Peter Cordes May 25 '22 at 19:21
  • https://godbolt.org/z/aT8dhWGrd – xiver77 May 25 '22 at 20:33

0 Answers0