Yes, the solutions below are a smart way to always have carry bit to tell
if we had an overflow.
Only problem is that in case when the add/sub of the lower byte resulted in
a carry that made the inc/dec to wrap: the high byte does not get
added/subtracted! (or am I just too tired this late on a friday?)
And this effect will cause problem if we try to expand to more bytes.
Is there a smart solution to both get the carry correct, and also always
get the addition/subtraction correct?
Regards
/Morgan
At 19:57 1998-10-04 +0300, you wrote:
{Quote hidden}>Hello Ian.
>
>Why not use the same idea as for addition.
>At final the Cy=1 if no borrow was taken else Cy=0.
>
> movfw Word1Low
> subwf Word2Low,f
>
> movfw Word1High
> skpc ;if Cy=1 then simply subwf
> incfsz Word1High,w ;if Cy=0 then subwf with borrow
> subwf Word2High,f ;if Word1High+1 ==0 then skip SUBWF
> ;command to save the Cy flag
>
>You may easy to add one more byte subtraction like a second block
>in example above.
>
>Be luck in your research ! ;-)
>
>WBR Dmitry.
>
>Ian Parish wrote:
>>
>> I'm new to this list so this may have been answered before.
>> I'm looking for a neat code snippet for word subtract for the 16F84.
I've found some info for word add (on Dejanews) but I can't seem to extend
this simply to subtract.
{Quote hidden}>>
>> for word add I've got:-
>>
>> MOVF Word1Low,W
>> ADDWF Word2Low,F
>> MOVF Word1High,W
>> BTFSC STATUS,C
>> INCFSZ Word1High,W
>> ADDWF Word2High,F
>>
>> ... which produces Word2 += Word1, with carry correctly set!
>> Any ideas?
>
>
Morgan Olsson ph +46(0)414 70741
MORGANS REGLERTEKNIK fax +46(0)414 70331
H€LLEKS (in A-Z letters: "HALLEKAS")
SE-277 35 KIVIK, SWEDEN .....mrtKILLspam
.....iname.com
___________________________________________________________