I believe that code generated for a 32x32 bit multiply (not directly supported by MAC hardware) is incorrect. I have tried 4.27 and 5.05 compiler versions on XC167 with #pragma MAC, getting same (wrong) results. 16: long mac (long a, long b) 17: { 18: long c; 19: c = a * b; 00C00032 F048 MOV R4,R8 00C00034 F059 MOV R5,R9 00C00036 F06A MOV R6,R10 00C00038 F07B MOV R7,R11 00C0003A CA00AA00 CALLA+ CC_UC,?C_COLMUL(0xC000AA) 00C0003E F064 MOV R6,R4 00C00040 F075 MOV R7,R5 20: return (c); 21: } ?C_COLMUL: 00C000AA A3560000 CoMULu R5,R6 00C000AE A3471000 CoMACu R4,R7 00C000B2 A3008240 CoSHL #0x00 00C000B6 A3008240 CoSHL #0x00 00C000BA A3461000 CoMACu R4,R6 00C000BE C3550800 CoSTORE R5,MAH 00C000C2 C3442000 CoSTORE R4,MAL 00C000C6 CB00 RET
Yes, there is a problem in the C166 library function. It was written for the ST10F2xx parts where the CoSHL instruction has a different encoding. For Infineon XC16x the usage of the MAC makes little sense, since the standard multiply instruction also performs in one cycle. The problem will be solved in the next C166 revision. Jon