5.19 __multiply_unsigned Intrinsic Function
The IAR __multiply_unsigned
intrinsic function provides access to the
mul
instruction.
Suggested Replacement
There is no MPLAB XC8 equivalent built-in function; however, the instruction can be inserted explicitly using in-line assembly code.
Use in-line assembly to directly write an mul
instruction.
Caveats
None
Examples
Consider migrating IAR code such
as:
unsigned int operation(unsigned char x, unsigned char y)
{
unsigned int result = __multiply_unsigned(x, y);
return result;
}
to
MPLAB XC8 code similar
to:#include <xc.h>
unsigned int multiply_unsigned(unsigned char x, unsigned char y)
{
unsigned int z;
__asm__("mul %1, %2 \n\t"
"movw %0, r0 \n\t"
"clr __zero_reg__ \n\t"
: "=r" (z)
: "r" (x), "r" (y));
return z;
}
unsigned int operation(unsigned char x, unsigned char y)
{
unsigned int result = multiply_unsigned(x, y);
return result;
}
Further Information
See the In-line Assembly section in the MPLAB XC8 C Compiler User's Guide for AVR MCUs for more information on adding in-line assembly.