简体   繁体   English

ARM Assembly中的SMMUL指令

[英]SMMUL instruction in ARM Assembly

Refer to: http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0553a/CHDHGFEF.html 请参阅: http : //infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0553a/CHDHGFEF.html

Writes the most significant signed 32 bits of the result in Rd.

SMMUL is meant to multiply to vairable together but I do not understand how it calculates the "most significant signed 32 bits of the result" SMMUL的目的是要相乘成vairable,但我不明白它如何计算“结果的最高有效32位”

Thanks in advance 提前致谢

When you multiply 2 32-bit value you get a 64-bit value and you have to save the result in two registers since a register is 32-bit. 当将2个32位值相乘时,您将得到一个64位值,并且由于一个寄存器是32位,因此必须将结果保存在两个寄存器中。 However may be you are not interested in lowest 32-bit and only highest 32-bit. 但是,可能您对最低的32位和最高的32位不感兴趣。

SMULL instruction provides you that. SMULL指令为您提供。 first calculates 64-bit result then it may simply discard/truncate lower 32-bits or it can round them into higher 32-bits ( SMULLR ). 首先计算64位结果,然后可以简单地丢弃/截断较低的32位,也可以将它们舍入为较高的32位( SMULLR )。

$ cat smmul.c 
int smull(int a, int b, int c, int d) {
    asm volatile("smmul r0, r2, r3");
}

int main() {
    int a, b, c;
    a = 0x00000001;
    b = 0x00000001;
    c = smull(0, 0, a, b);
    printf("%x(%d) %x(%d) %x(%d)\n", a, a, b, b, c, c);
    a = 0x40000000;
    b = 0x00000004;
    c = smull(0, 0, a, b);
    printf("%x(%d) %x(%d) %x(%d)\n", a, a, b, b, c, c); 
    return 0;
}

$ smmul
1(1) 1(1) 0(0)
40000000(1073741824) 4(4) 1(1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM