Vault 7: Projects
This publication series is about specific projects related to the Vault 7 main publication.
16-bit MCU and DSC Programmer’s Reference Manual
DS70157F-page 480 © 2005-2011 Microchip Technology Inc.
Example 6-1: Additional Inline Functions
#include "p33fxxxx.h"
volatile long Result_mpy1616;
volatile long Result_addab;
volatile long Result_subab;
volatile long Result_mpy3216;
volatile long Result_div3216;
register int Accu_A asm("A");
register int Accu_B asm("B");
inline static long mpy_32_16 (long, int);
inline static long mpy_32_16 (long x, int y)
{
long result;
int temp1, temp2;
temp1 = (x>>1)&0x7FFF;
temp2 = x>>16;
Accu_A = __builtin_mpy (temp1, y, 0,0,0,0,0,0);
Accu_A = __builtin_sftac (15);
Accu_A = __builtin_mac (temp2, y, 0,0,0,0,0,0,0);
asm("mov _ACCAL,%0\n\t"
"mov _ACCAH,%d0" : "=r"(result) : "w"(Accu_A));
return result;
}
int main (void)
{
// Variable declarations
int Input1;
int Input2;
int Input3;
int Input4;
long Input5;
int Input6;
long Input7;
int Input8;
// Enable 32-bit saturation, signed and fractional modes for both ACCA
and ACCB
CORCON = 0x00C0;
// Example of 16*16-bit fractional multiplication using ACCA
Input1 = 32767;
Input2 = 32767;
Accu_A = __builtin_mpy (Input1, Input2, 0,0,0,0,0,0);
asm("mov _ACCAL,%0\n\t"
"mov _ACCAH,%d0" : "=r"(Result_mpy1616) : "w"(Accu_A));
// Example of 16*16-bit fractional multiplication using ACCB
Input3 = 16384;
Input4 = 16384;
Accu_B = __builtin_mpy (Input3, Input4, 0,0,0,0,0,0);
asm("mov _ACCBL,%0\n\t"
"mov _ACCBH,%d0" : "=r"(Result_mpy1616) : "w"(Accu_B));
// Example of 32-bit addition using ACCA (ACCA = ACCA + ACCB)
Accu_A = __builtin_addab();
asm("mov _ACCAL,%0\n\t"
"mov _ACCAH,%d0" : "=r"(Result_addab) : "w"(Accu_A));
// Example of 32-bit subtraction using ACCB (ACCB = ACCB - ACCA)
Accu_B = __builtin_subab();
asm("mov _ACCBL,%0\n\t"
"mov _ACCBH,%d0" : "=r"(Result_subab) : "w"(Accu_B));
// Example of 32*16-bit fractional multiplication using ACCA
Input5 = 0x7FFFFFFF;
Input6 = 32767;
Result_mpy3216 = mpy_32_16 (Input5, Input6);
while(1);
}
Protego_Release_01_05-Related-OEM-Documentation-PIC24FJ64GA004-Programmers_Reference_Manual.pdf