I assume you have an 8 bit signed value and would like to add it to a 16 bit signed, right? The 2's complient had already been explained to you, so you know you do not have to worry about whenever your value is negative or positive as long as both numbers represented in 8 bits. But you have to add that 8 bits to 16 so you have to extend it first like this: clrf tmp ; high value of input is now 0x00 btfsc WREG, 7 comf tmp,f ; oh, that's a negative one? put 0xFF instead so if WREG is positive tmp holds 0 but if negative holds 0xFF. So now all you have to do is to add the two 16 bit numbers as normal: addwf blahL,f movf tmp, W addwfc blahH,f If you would like to extend it to add two 16 signed numbers then all you have to do is to forget the first 3 instruction which just expands the 8 bit signed to 16 one... Do not forget that there are always some tricks to avoid using extra memory space and save some cycles :-) addwf blahL,f ; that's standard btfsc STATUS, C incf blahH ; add carry to the high byte btfsc WREG, 7 decf blahH ; erm, negative number, adjust high byte With this one you saved 1 cycle and no more RAM needed -- but you can't extend this to add two 16 signed. Regards, Tamas On 14/07/06, Bob J. wrote: > > Sorry guys I fat fingered my previous message. Here's the rest of it. > > Guys, I have a value in W that's signed. Adding this value to a set of > two > variables is easy enough: > addwf blahL,f > clrf wreg > addwfc blahH,f > > W contains a signed value. If the value of W is a negative, doing the > following doesn't work (to subtract it instead of adding it.) > > addwf blahL,f > clrf wreg > bnc subtract > addwfc blahH,f > subtract > subwfb, blahH,F > > I see why this is incorrect, but I'm not sure how you test for a 2's > complement value in order to properly skip the subtraction if the value in > W > is not setting the carry or borrow flag when adding the lower byte. Can > someone please steer me down the correct path? > > Regards, > Bob > > > > > > On 7/14/06, Bob J. < rocketbob@gmail.com> wrote: > > > > Guys, I have a value in W that's signed. Adding this value to a set of > > two variables is easy enough: > > > > addwf blah,f > > clrf wreg > > addwfc > > > -- > 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