User guide

int tmp;
__asm
{
MRS tmp, CPSR
ORR tmp, tmp, #0x80
MSR CPSR_c, tmp
}
}
int main(void)
{
disable_IRQ();
enable_IRQ();
}
Dot product
Example 4-3 calculates the dot product of two integer arrays. It demonstrates how inline assembly language can
interwork with C or C++ expressions and data types that are not directly supported by the inline assembler. The inline
function mlal() is optimized to a single SMLAL instruction. Use the -S -fs compiler option to view the assembly
language code generated by the compiler.
long long is the same as __int64.
This code is also in install_directory\examples\inline\dotprod.c.
Example 4-3 Dot product
#include <stdio.h>
/* change word order if big-endian
#define lo64(a) (((unsigned*) &a)[0]) /* low 32 bits of a long long */
#define hi64(a) (((int*) &a)[1]) /* high 32 bits of a long long */
__inline __int64 mlal(__int64 sum, int a, int b)
{
#if !defined(__thumb) && defined(__TARGET_FEATURE_MULTIPLY)
__asm
{
SMLAL lo64(sum), hi64(sum), a, b
}
#else
sum += (__int64) a * (__int64) b;
#endif
return sum;
}
__int64 dotprod(int *a, int *b, unsigned n)
{
__int64 sum = 0;
do
sum = mlal(sum, *a++, *b++);
while (--n != 0);
return sum;
}
int a[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int b[10] = { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };
int main(void)
{
printf("Dotproduct %lld (should be %d)\n", dotprod(a, b, 10), 220);
return 0;
}
Long multiplies
You can use the inline assembler to customize functions that use long long type. Example 4-4 shows a simple long
multiply routine in C.
Example 4-5 shows how you can use inline assembly language to generate different code for the same routine. You
can use the inline assembler to write the high word and the low word of the long long separately.
The inline assembly language code depends on the word ordering of long long types, because it assumes that the
low 32 bits are at offset 0. Change the code if compiling for big-endian.
This code is also in install_directory\examples\inline\smull.c.
Example 4-4 Multiply in C
Mixing C, C++, and Assembly Language
Copyright ?1999 2001 ARM Limited 4-6