Searching \ for 'Word (or more) subtract on 16F84' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/microchip/devices.htm?key=16F
Search entire site for: 'Word (or more) subtract on 16F84'.

Truncated match.
PICList Thread
'Word (or more) subtract on 16F84'
1998\10\04@094648 by Ian Parish

flavicon
picon face
Hi,

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.

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?

Also, does anyone have the URL of a searchable acrhive for this list?

Thanks

Ian

1998\10\04@120145 by Dmitry Kiryashov

flavicon
face
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 foun
d some info for word add (on Dejanews) but I can't seem to extend this simply to
subtract.
{Quote hidden}

1998\10\04@201718 by Regulus Berdin

flavicon
face
Ian Parish wrote:
> I'm looking for a neat code snippet for word subtract for the 16F84. I've foun
d some info for word add (on Dejanews) but I can't seem to extend this simply to
subtract.
{Quote hidden}

Hi,

There is a complete set of 16bit routines in Myke Predko's site and
explaining this routine. Check http://www.myke.com

Reggie

1998\10\05@171943 by Adam Bryant

flavicon
face
Go to http://www.myke.com.  Myke Predko has 16 bit code examples for addition,
subtraction, multiplication, division, and compare.  I am using all 5
operations in an RC servo mixer and they work great.





spam_OUTIanTakeThisOuTspamALLANON.DEMON.CO.UK on 10/04/98 03:40:00 AM

Please respond to .....PICLISTKILLspamspam@spam@MITVMA.MIT.EDU

To:   PICLISTspamKILLspamMITVMA.MIT.EDU
cc:    (bcc: Adam Bryant/PEAK/MOORE)
Subject:  Word (or more) subtract on 16F84




Hi,
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.
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?
Also, does anyone have the URL of a searchable acrhive for this list?
Thanks
Ian

1998\10\08@163239 by myke predko

flavicon
face
Adam Bryant Wrote:

>Go to http://www.myke.com.  Myke Predko has 16 bit code examples for addition,
>subtraction, multiplication, division, and compare.  I am using all 5
>operations in an RC servo mixer and they work great.

Wow!  That sounds like an interesting application.  If you get some time,
I'd be interested in seeing it.

Just a note about the 16 bit operations, they produce the correct 16 bit
value, but the carry (ie set after addition result > 65,536) may not be
correct.  This is an issue in some applications; most typically, I see other
add/subtract code snippets which keep the carry correct for noting that an
out of bound condition exists - the problem is that they don't produce the
correct 16 bit result.

Hmmm...  Maybe I should come up with a snippet that does both.

Regarding the HP 16C calculator thread; I guess I'm a genius.  When I was at
school, I bought two of them (one for work, one for home).  They are the
best programmer's calculators any developed - I would be lost without mine.
I just wish HP would come up with an updated version.

Sorry, I've been away for a few days; if you've sent me a note and are
looking for a reply, I'll get to it in the next few days.

Toodles,

myke

Look at the accomplishments and people that made them happen over the past
1,000 years in "The LIFE Millennium".

http://www.myke.com/Book_Room/book1a.htm

1998\10\30@160035 by Morgan Olsson

picon face
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}

I've found some info for word add (on Dejanews) but I can't seem to extend
this simply to subtract.
{Quote hidden}

       Morgan Olsson                   ph  +46(0)414 70741
       MORGANS REGLERTEKNIK            fax +46(0)414 70331
       H€LLEKS           (in A-Z letters: "HALLEKAS")
       SE-277 35 KIVIK, SWEDEN               .....mrtKILLspamspam.....iname.com
___________________________________________________________

1998\10\31@150218 by Chip Weller

flavicon
face
Morgan Olsson wrote:


>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?)

                                 ===============================
Yes, the only time the last add or subtract is skipped is when the value to
add or subtract is zero. The carry bit and the 16-bit results are both
correct in all cases.

Chip.

More... (looser matching)
- Last day of these posts
- In 1998 , 1999 only
- Today
- New search...