Floating point (SSE)

The XMM registers

x86-64 floats live in sixteen 128-bit XMM registers. SSE2 is baseline on every x86-64 CPU, so scalar double arithmetic uses the SD (scalar double) forms: movsd, addsd, subsd, mulsd, divsd:

movsd xmm0, [pi] addsd xmm0, xmm1 mulsd xmm0, [two]

SSE arithmetic

Each instruction takes two operands like the integer ones: destination first, source second, both either XMM registers or one memory operand. Comparisons set the integer flags, so COMISD plus a conditional jump branches on a float comparison:

comisd xmm0, xmm1 ja xmm0_greater jb xmm0_less

Printing a double

To print a double, pass it in XMM0 to printf with a %f format string, set AL to 1 (one vector register used), and link against libc. Raw sys_write has no float formatting: convert to text yourself, or use printf.

The code on this page was assembled with NASM 3.01 and linked with gcc 15.2.0, and the program was run on Alpine Linux 3.24.3 (x86_64) in a Docker container.

Article author: Arthur Isaev