At my university we were just introduced to IA32 SSE. What I am trying to do is to add two vectors (They call it a "packed value", it means that the vector contains four 32-bit single precision floating point numbers. One verctor's size is 128 bit.) Here's what I am trying to do:
%xmm0 | 5.5 | 1.2 | 2.4 | 7.0 |
%xmm1 | 3.0 | 1.5 | 3.5 | 2.2 |
| | | |
+ + + +
| | | |
V V V V
%xmm0 | 8.5 | 2.7 | 5.9 | 9.2 |
However, on the slides they only show the following code snippet which I simply don't get to work:
# %eax and %ebx contain the addresses of the two vectors that are to be added
movups (%eax), %xmm0
movups (%ebx), %xmm1
addps %xmm1, %xmm0
movups %xmm0, result
This raises two questions:
1. How do I even create these vectors in the first place and how do I make %eax and %ebx point to them?
2. How do I print the result in order to check whether the operation was successful or not?
Here's what I tried. The following code compiles and does not crash when I run it. However, there's no output at all... :/
.data
x0: .float 7.0
x1: .float 2.4
x2: .float 1.2
x3: .float 5.5
y0: .float 2.2
y1: .float 3.5
y2: .float 1.5
y3: .float 3.0
result: .float 0
intout: .string "Result: %f.\n"
.text
.global main
main:
pushl x3
pushl x2
pushl x1
pushl x0
movl %esp, %eax
pushl y3
pushl y2
pushl y1
pushl y0
movl %esp, %ebx
movups (%eax), %xmm0
movups (%ebx), %xmm1
addps %xmm1, %xmm0
movups %xmm0, result
pushl result
pushl $intout
call printf
addl $40, %esp
movl $1, %eax
int $0x80