Search code examples
linuxassemblyx86-64fasm

Sum using XMM registers using FASM under Linux OS


Sum using xmm regsisters using fasm - linux:

$./fasm file.asm
$ gcc -s file.o -o file -lm

The result should be 14 , but I got 7.000000000000000000000000000000.

This is the source code:

format elf64
extrn printf

section '.data' writeable align 16
rad dq 7.0
fmt db "%.30lf",0ah,0

section '.text' executable align 16
public main
main:
    push rbp
    mov rbp,rsp
    pxor xmm0,xmm0
    movsd xmm0,[rad]
    pxor xmm2,xmm2
    movsd xmm2,[rad]
    addsd xmm2,xmm0
    mov rax,1
    mov rdi,fmt
    call printf

    mov rsp,rbp
    pop rbp
    ret

Solution

  • Solve it :

    format elf64
    extrn printf
    
    section '.data' writeable align 16
    rad dq 7.0
    fmt db "%.30lf",0ah,0
    
    section '.text' executable align 16
    public main
    main:
        push rbp
        mov rbp,rsp
        pxor xmm0,xmm0
        movsd xmm0,[rad]
        movsd xmm2,[rad]
        addsd xmm0,xmm2
        mov rax,1
        mov rdi,fmt
        call printf
    
        mov rsp,rbp
        pop rbp
        ret