User guide

Writing the multiply routine in C:
// long multiply routine in C
long long smull(int x, int y)
{
return (long long) x * (long long) y;
}
The compiler generates the following code:
MOV r2,r0
MOV r0,r1
MOV r1,r2
SMULL r12,r1,r0,r2
MOV r0,r12
MOV pc,lr
r12 is corrupted in this routine. This is allowed under ATPCS.
Example 4-5 Multiply in inline assembly language
Writing the same routine using inline assembly language:
long long smull(int x, int y)
{
long long res;
__asm { SMULL ((int*)&res)[0], ((int*)&res)[1], x, y }
return res;
}
The compiler generates the following code:
MOV r2,r0
SMULL r0,r1,r2,r1
MOV pc,lr
Mixing C, C++, and Assembly Language
Copyright ?1999 2001 ARM Limited 4-7