I'm pretty new to this microcontroller stuff. However, many years ago I did some "low level" programming on the 6502. Hence my suprise that there is no ADD with CARRY on the 16F devices (well, there isn't on the 16F628 anyhow) - because over 20 years ago the 6502 had it! I'm sure there's a reason, but it did make addition over multiple bytes pretty easy, so 24-bit, 32-bit or 40-bit addition was no problem. However, with the 16F I can't see how to do this "officially", so I cobbled together the macro below to emulate the ADDWFC I have read about on the 18F devices.
addwfc MACRO file ;ADD W to File with Carry btfsc STATUS,C goto $+3 ;goto carry addwf file,F goto $+9 ;goto end addwf file,F incf file btfsc STATUS,C goto $+4 ;goto set_carry btfsc STATUS,Z goto $+2 ;goto set_carry goto $+2 ;goto end bsf STATUS,C endm
to use it in code (for 24-bit addition)...
bsf STATUS,C movfw B_L addwfc A_L
movfw B_M addwfc A_M
movfw B_H addwfc A_H
and the answer is put back in A_[H,M,L].
Is this using a sledgehammer to crack a nut? Am I missing something? Can this macro be improved? Is there an easier way? Bearing in mind that subtraction (with 2's compliment) can also be performed with ease with this command. It would then be only 23-bit in magnitude if you didn't want to use signed numbers for anything other than for the purposes of subtraction.
Regards,
Dave Giblin Lancashire England