Click here to Skip to main content
15,883,705 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
why is my output all zeros and not {3,3,3,3}?
C++
#include "stdafx.h"
#include <iostream>
#include "emmintrin.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
    short x0[4]={1,1,1,1};//array xo
    short x1[4]={2,2,2,2};//array x1
    short c[4]; // sum of x0 and x1
    __asm{
    movq mm4,x0 // load x0 into mm4
    movq mm7,x1 // load x1 into mm7
    paddw mm4,mm7// add array x0 to array x1
    movq mm5, mm1
    movq c,mm1  // move result into xmm1
   emms
    }
for (int i = 0; i < 4; i++)
       {
           cout << x0[i] << " ";
           cout << x1[1]<< " ";
          cout << endl;
       }
        cout << endl;
       for (int i = 0; i < 4; i++)
       {
            cout << c[i] << " ";
          cout << endl;
       }

    return 0;
}
Posted
Updated 11-Jul-10 2:20am
v2

1 solution

The answer is very simple: the instruction paddw mm4, mm7 add each word in the mm4 register to the correspondant word in the mm7 register, and put the result in the mm4 register.

Then remove the two lines movq mm5, mm1 and movq c, mm1, and replace them with movq c, mm4.
 
Share this answer
 
Comments
SMART LUBOBYA 13-Jul-10 12:29pm    
Reason for my vote of 5
this is really educative

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900