Hi there, I am trying to implement 32 bit addition and subtraction routines but I have some problems with the carry management. Before reinventing the wheel I have done a search (on the piclist archive, on the Mchip AppNotes and on some Web sites) just to see if there is something ready made. I have found nothing appropriate: just some 16 bit routines (I know is out there but I can't find it. The Web is really frustrating!). Ok. I will take a 16 bit add routine and I will extend it to 32 bit. I found a Microchip AppNote (the AN617: Fixed Point Routines) that has, among others, an "expandable" 16 bit add. Here it is: ADD MOVF AARGB1,W ADDWF BARGB1 MOVF AARGB0,W BTFSC _C INCFSZ AARGB0,W ADDWF BARGB0 And this is the text following the routine: The four instructions after the initial add/subtract, can be easily concatenated for operations involving more than two bytes. Because addition and subtraction are required in standard algorithms for multiplication and division, these issues permeate the implementation of both fixed and floating point algorithms for the PIC16C5X/PIC16CXXX families. So essentially I sum the LSB, if there is a carry (as in 0x90+0x80=0x10+carry) I have to increment the LSB+1 of AARG before summing it BARG. The writer of the cited note says me I can repeat the process on next bytes because at every sum I have the carry set if the operation result overflows. Right? I don't think so!. Try this sum: 0x0001ff90+0x00013080=0x00033010 We have (from LSB to MSB): take 0x90, sum 0x80, store 0x10 + set the carry flag take 0xff, increment to 0x00, sum 0x30, store 0x30 + RESET THE CARRY FLAG because 0x00+0x30 doesn't overflow take 0x01, sum 0x01, store 0x02 + reset carry take 0x00, sum 0x00, store 0x00 + reset carry The final result is: 0x00023010!! Quite different from the correct answer. The problem arises for every AARG with a 0xFF byte (except for LSB). Am I completely wrong or the Microchip AppNotes are buggy? (I heard some rumors about that :) I have tried to solve the puzzle but I can't work out an elegant solution. I am sure someone had solved this problem already. PLEASE, do you have some good advice to spare? Thanks Marco BTW: The subtraction routine had the same structure and comment. I think I actually have two problems. ---- Marco DI LEO email: m.dileo@sistinf.it Sistemi Informativi S.p.A. tel: +39 6 50292 300 V. Elio Vittorini, 129 fax: +39 6 5015991 I-00144 Roma Italy