Hi Daniel, Yes, that's ok, the only thing is that as I can see Dwayne's original code what he needs is: B[012] = A[012] + K[012] So up front of your solution the A is needed to copy to B which is 6 additional instructions. That's 6+11 or if you combine the first add with the move then it'll be 5+10. In my interpretation the question is if there is a better solution than the claimed 14 cycles without the ADDWFC instruction. What I was thinking of is a 13 cycle version using rlf - could not test it as I'm on a holiday far away from my computer, so it could be wrong... ; B[012]: dest; A[012]: src; K[012]: const clrf B1 clrf B2 movlw K0 addwf A0,w movwf B0 rlf B1 ; carry in middle octet movlw K1 addwf A1,w rlf B2 ; carry in high octet (const+src is overflown) addwf B1,f ; here cannot overflown as ; const+src is max FF+FF=FE so FE+1 is FF... movlw K2 addwf A2,w addwf B2,f Tamas On Dec 29, 2007 2:35 AM, Daniel Serpell wrote: > Hi! > > On Dec 22, 2007 1:04 AM, Dwayne Reid wrote: > > Good day to all. > > > > I'm working on a short routine where I add a 24 bit constant to a 24 > > bit variable. > > > > My previous method has been to load the constant into 3 bytes of RAM, > > then use the standard multi-byte addition routines to add the > > variable to the RAM value. Takes 6 + 10 instruction cycles; or, if > > I'm feeling energetic: 5 + 10 instruction cycles. Really energetic: > > 14 instruction cycles. > > > > I've been doing it that way for years - no problems. > > > > But it bugs me. I should be able to figure out a generic method for > > adding a multi-byte constant to a multi-byte variable without having > > the intermediate step of loading the 3 literals that form the 24-bit > > constant into RAM. > > > > Well, there is a better way, the minimum is 9 instructions for RAM to > RAM and 11 cycles for RAM and literal: > > ; 9 inst add, A[012] = A[012] + B[012]: > movf B0,W > addwf A0,F > movf B1,W > btfsc STATUS,C > incfsz B1,W > addwf A1,F > rlf B2,W > subwf B2,W > subwf A2,F > > ; 11 inst add, A[012] = A[012] + K[012] > movlw K0 > addwf A0,F > movlw K1 > btfsc STATUS,C > addlw 0x01 > btfss STATUS,C > addwf A1,F > movlw K2 > btfsc STATUS,C > addlw 0x01 > addwf A2,F > > In general, to add N byte numbers, you need 4*N-3 instructions > if the numbers are in RAM, or 5*N-4 if you need to add a literal > value. If you need a correct C flag after the add, one more > instruction is needed. > > Those were found using my super-optimizer: > http://daniel.serpell.googlepages.com/picmicrocontrollersuperoptimizer > > You can do better if some part of the constant is 0. > > Daniel. > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist