将GCC内联汇编编译到Microsoft Visual C ++ 2008中

时间:2014-02-03 22:55:06

标签: c gcc assembly arm inline-assembly

我无法将此GCC内联汇编编译为Microsoft Visual C ++ 2008程序集

GCC内联汇编:

__asm__(
    "smull %0, %1, %2, %3     \n\t"
    "mov   %0, %0,     LSR #16 \n\t"
    "add   %1, %0, %1, LSL #16  \n\t"
    : "=&r"(lo), "=&r"(hi)
    : "r"(rb), "r"(ra));

编译器说:

错误C2143:语法错误:缺少')'之前':'

完整的功能是:

static __inline Word32 mull(Word32 a, Word16 b)
{
    register Word32 ra = a;
    register Word32 rb = b;
    Word32 lo, hi;

    __asm__(
        "smull %0, %1, %2, %3     \n\t"
        "mov   %0, %0,     LSR #16 \n\t"
        "add   %1, %0, %1, LSL #16  \n\t"
        : "=&r"(lo), "=&r"(hi)
        : "r"(rb), "r"(ra));

    return hi;
}

感谢。

1 个答案:

答案 0 :(得分:1)

Visual Studio不支持ARM内联汇编。见:Inline assembly is not supported on the ARM。您需要将汇编代码反向工程为C,或者使用单独的汇编程序并将其作为单独的函数进行链接。

看起来这个函数只做32 x 32 - > 64位有符号乘法,然后将64位结果右移16位并将其截断为32位:

static __inline Word32 mull(Word32 a, Word16 b)
{
    return (Word32)(((Word64)a * (Word64)b) >> 16);
}