> I hate C too, so here is my code: > > ; Xvar=Xvar*2+1 > movf Xvar,w ;put X in W > addwf Xvar,f ; add W to X (X*2) > incf Xvar,f ; add 1 (x*2+1) > > Note that the result is modulo 256 so it's working only if X<127. Thus you > can check the C flag for overfolw and use it also for X>127 The other methods do this too. There is no need for a third instruction: bsf status, c ;set value of bit to shift in rlf x ;shift left (X*2), shift in 1 (X*2 + 1) Or: rlf x ;shift left (X*2), garbage in low bit bsf x, 0 ;explicitly set low bit for the added 1 Either way the C flag is set if an overflow occurred, since a 1 bit would have been shifted out by the RLF instruction. ***************************************************************** Embed Inc, embedded system specialists in Littleton Massachusetts (978) 742-9014, http://www.embedinc.com -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu