> >I know of no > >other good way to, e.g., perform an add-with-carry that produces a meaningful > >carry out: > > > > movf Source,w > > btfsc C > > incfsz Source,w > > addwf Dest,f > > > >[does anyone know who invented that ingenious piece of code? They should > >win an award or something...] > > John, > > Please continue with the explanation of this one, I'm not quick enough to > figure out what you're doing. I don't know of any good explanation for the code, except to describe it as follows: If the carry was set, then... If the source operand was 255... We'd be adding 256, which means the destination should have zero added and the carry should be set. Since adding zero to the destination would leave it unchanged, and since the carry is already set, we can simply do nothing. Otherwise... Add the source, plus one, to the destination; the carry will do what it will. Otherwise... Add the source to the destination; the carry will do what it will. I have no idea who invented that ingenious piece of code, but it really is quite remarkable. Unfortunately, I know of no good way to do such an add for the case of dest=source1+source2, other than coding it as dest=source1; dest+=source2. By the way, when adding a constant, it's possible to shave off an instruction if a "known-zero" location exists. Assuming a 16C84 [address $7F will always read zero], the following are I think the best approaches. Note that unlike the 'add a variable' routine above, these lend themselves readily to the case 'dest=source+const'. ; If constant is zero: rlf KZ,w ; KZ=known-zero @ $7F addwf Dest,f ; Or addwf Source,w // movwf Dest ; If constant is 1-254: rlf KZ,w addlw Const addwf Dest,f ; If constant is 255: [dest+=255] movlw 255 btfss C addwf Dest,f ; If constant is 255: [dest=source+255] movf Source,w btfss C addlw 255 movwf Dest,f I think these approaches are the best possible. Anyone know of anything shorter?