>
>Per my understanding. If I do a subtraction and the C bit is 1, everything
>went okay and use the result. Otherwise C is 0 and the borrow bit occurred and
>I then can use two's complement to get it corrected. Is this correct as shown
>below.
>
>Thanks.
>
>movf TEMP, W
> subwf TEMP1, W
> btfss STATUS, C
> goto DONE
> comf W
> incf TEMP1, W
>
>Caisson wrote:
>
>> > Van: John Considine <
@spam@jconsiKILLspam
MAGICNET.NET>
>> > Aan:
KILLspamPICLISTKILLspam
MITVMA.MIT.EDU
>> > Onderwerp: Re: Thanks Dan Larson subtract smaller # from Larger #
>> > Datum: woensdag 3 november 1999 19:21
>>
>> This "solution" only works for numbers upto 127. Subtracting 2 from 200
>> would give a *valid* number, but with the sign-flag set. So the "solution"
>> would mangle it into something else :-( Where the Sign-flag is the
>> Over/underflow for small numbers (0 thru 127), the Carry is the Overflow
>> for large numbers (0 thru 255) ...
>>
>> You can still use the Two-complement trick though, just replace the check
>> for the Sign-flag with a check for the Borrow-flag ( NOT Carry-flag).
>>
>> Regards,
>> Rudy Wieser
>>
>> > Very ingenious, I never would have though of the two's complement after
>> > already having done the original subtraction.
>> >
>> > Thanks.
>> >
>> > Dan Larson wrote:
>> >
>> > > On Wed, 3 Nov 1999 10:08:20 -0500, John Considine wrote:
>> > >
>> > > >I am trying to make sure that I subtract a smaller number from a
>> larger
>> > > >number. However, when the subwf does the two's complement apparently
>> it
>> > > >sets the C flag. For example, Value1 = H'5C' and Value2 = H'72'
>> causes
>> > > >C to be set. Even though 72 is greater than 5C.
>> > > >
>> > > >How does everybody else check that a smaller number is being
>> subtracted
>> > > >from a larger number?
>> > >
>> > > How about just doing the subtract, regardless of operand order.
>> > > Then, check the sign bit (bit seven). If bit 7 is set, complement
>> > > and increment the result (two's complement). If bit 7 is not set,
>> > > then leave the result alone. The result will be the absolute value
>> > > of the difference. Is this what you want?
>> > >
>> > > ; Using three RAM location and preserving Value1 and value2
>> > >
>> > > movf Value1, W
>> > > movwf Result
>> > > movf Value2, W
>> > > subwf Result, F
>> > > btfss Result, 7
>> > > goto Done
>> > > comf Result, F
>> > > incf Result, F
>> > > Done:
>> > >
>> > > ; Using two RAM locations and destroying Value2
>> > >
>> > > movf Value1, W
>> > > subwf Value2, F
>> > > btfss Value2, 7
>> > > goto Done
>> > > comf Value2, F
>> > > incf Value2, F
>> > > Done:
>> > >
>> > > I hope this helps you...
>> > >
>> > > Dan
>