3 byte (24bit) ADD

;The PIC ADD instruction adds a register to Accumerlator and stores the result either back in the register or in the Accumerlator. ; Cy and Z flags are set on the result, however the PIC has no 'add with Carry' instruction, which makes multi-byte addition more difficult than it should be. ; ;So, adding 2 values, a and b, in registers, hi,mid,lo bytes, source 'a', destination 'b' ; (using INDF pointers takes longer as we have to INC to aim at each next byte) ADD24 ;subroutine ; 'a' 3 bytes in aRegHi,Mid,Lo are added into destination 'b' 3 bytes (so b=a+b) ; Acc is lost, Cy if last byte add overflows, a is preserved, b is the result COPY aRegLo,Acc ADD Acc,bRegLo ;first add, sets Cy if b overflow Skip nCy ;skip if no carry INCFSZ bRegMid ;CY, inc Bmid - if that results in 'zero' then bMid overflowed DEC bRegHi ;OK, here on nCy or if inc bRegMid did NOT overflow = pre-DEC bHi INC bRegHi ;here on bMid overflow (so overflow == INC, without pre-DEC), but if Hi overflows, too bad ; OK now add the mid bytes COPY aRegMid,Acc ADD Acc,bRegMid ;as before, could Cy Skip nCy INC bRegHi ;inc B Hi, if Hi overflows too bad ; finally ADD hi bytes COPY aRegHi,Acc ADD Acc,bRegHi ;add final byte (overflow exits with Cy) RETURN ; ; Cy is set if the Hi byte ADD overflows, but not if the Hi byte overflows as a result of Cy out of Mid (or Lo) ... ; Total 13 instructions, 14 CLK's (includes 2 Return) ; ; Can you find a quicker way ? ;