NASM - The Netwide Assembler
NASM Forum => Programming with NASM => Topic started by: markallyn on March 13, 2017, 04:32:26 PM
-
Hello everyone,
I'm new to sse2 and trying to get the hang of printing results with printf. The following code prints out a simple greeting correctly. Then I try to add two packed doubles and print the results from xmm0.. The correct addttion can be seen using gdb and printing the two doubles stashed in xmm0. What printf prints is 3.3 and 2.2, not 3.3 and 5.5. I'm doing (not doing?) something right. Here's the code:
extern printf
extern exit
SEGMENT .data
fmt1 db "Getting started ...",0
fmt2 db "%s",13,10,0
fmt5 db "%f %f",13,10,0
align 16
val1 dq 1.1, 2.2
align 16
val2 dq 2.2, 3.3
SEGMENT .text
global _start
_start:
mov rdi, fmt2
mov rsi, fmt1
mov rax, 0
call printf
movapd xmm0, [val1]
movapd xmm1, [val2]
addpd xmm0, xmm1 ;xmm0 contains 3.3 and 5.5
mov rdi, fmt5
mov rax, 1
call printf ;printf prints 3.3 and 2.2
mov rdi, 0
call exit
Coompiled with: nasm -g -felf64 -F dwarf xmm.s and linked with: ld -dynamic-linker /lib64/ld-linker-x86-64.so.s -o xmm xmm.o -lc -lm
Could someone kindly suggest a solution?
Thanks,
Mark Allyn
-
I think you should put the higher half of XMM0 into the lower half of XMM1 and use RAX = 2 since you're using two XMM registers. printf reads lower halfs.
one way;
movapd xmm1,xmm0 ;copy
psrldq xmm1,8 ;shift right by 8 bytes
mov rdi,fmt5
mov rax,2
call printf
There are many others but the point is to get the higher xmm0 into lower xmm1 to get the second value.
-
dreamCoder:
Thanks, that was very helpful