I have the following program to print a float in asm with the help of C's printf
:
.section .rodata
format: .ascii "Your number is: %f\n\0"
.section .text
.globl main
main:
lea format(%rip), %rdi
mov $0b1000000001011001100110011001101, %xmm0 # the number 2.7
mov $0, %eax
add $-8, %rsp
call printf@plt
add $8, %rsp
mov $0, %eax
ret
However, I get an error when assembling it with:
int_c.s:7: Error: unsupported instruction `mov'
Are you not allowed to add immediates into the xmm
registers, or what seems to be the issue with the above program?
Update: I got it to compile but then I think my issue is that the movq
accepts 8 byte but I'm looking to get a 4-byte float into the fp register:
mov $2.7, %eax # using '2.7' to be more readable
movq %eax, %xmm0
And after stepping through the instructions it looks correct before calling printf
:
>>> p $xmm0
$2 = {
v4_float = {[0] = 2.70000005, [1] = 0, [2] = 0, [3] = 0},
v2_double = {[0] = 5.3194953090036137e-315, [1] = 0},
...
}