简体   繁体   中英

SMMUL instruction in ARM Assembly

Refer to: 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"

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. However may be you are not interested in lowest 32-bit and only highest 32-bit.

SMULL instruction provides you that. first calculates 64-bit result then it may simply discard/truncate lower 32-bits or it can round them into higher 32-bits ( 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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