Search code examples
cassemblyinline-assemblyvisual-c++-6visual-studio-6

How do I write the following inline assembly code in Visual C++ 6.0?


I am writing an application in C in GCC (for Linux/Ubuntu) that uses the following inline assembly.

float a[4] = { 10, 20, 30, 40 };
float b[4] = { 0.1, 0.1, 0.1, 0.1 };

asm volatile("movups (%0), %%xmm0\n\t"
             "mulps (%1), %%xmm0\n\t"
             "movups %%xmm0, (%1)"
             :: "r" (a), "r" (b));

Excuse typos in the above (I'm writing from memory). What is the equivalent inline assembler in Visual C++ 6.0 ? I have discovered that I need to port my code.


Solution

  • __declspec(align(16)) float a[4] = { 10, 20, 30, 40 };
    __declspec(align(16)) float b[4] = { 0.1f, 0.1f, 0.1f, 0.1f };
    
    __asm {
        movups xmm0, a; // could be movaps if array aligned
        mulps xmm0, b;
        movups b, xmm0; // could be movaps if array aligned
    }
    

    I'm not sure about Visual C++ 6, but it will work in Visual C++ 2008.