The intent of the CF_ bit is to make multiprecision adds and subtracts easier, as shown here:
;FF:= FF + GG with correct carry out (CF_ is 0) mov W, G ;add low bytes clrb STATUS.CF ;clear carry add F, W mov W, G+1 ;add high bytes and carry add F+1, W ;FF:= FF - GG with correct carry out (CF_ is 0) mov W, G ;subtract low bytes setb STATUS.CF ;set carry mov W, G+1 ;subtract high bytes
The following routines accomplish the same thing (although with an extra instruction), and they're compatable with the PIC 16C5x:
;FF:= FF + GG with correct carry out (CF_ is 1) mov W, G ;add low bytes add F, W mov W, G+1 ;get ready to add high bytes snb STATUS.CF ;skip if there was no carry into high byte movsz W, ++G+1 ;else add in carry; if result is 0 then high add F+1, W ; byte doesn't change and CF is still set ;FF:= FF - GG with correct carry out (CF_ is 1) mov W, G ;subtract low bytes sub F, W mov W, G+1 ;get ready to subtract high bytes sb STATUS.CF ;skip if there was no borrow from high byte movsz W, ++G+1 ;else increase amount to subtract by 1; if it's sub F+1, W ; 0 then high byte doesn't change, nor does CF
Since the carry-out is correct in all four of these routines, they can easily be extended for more bytes of precision.
We can do a double precision add in five instructions if there is a location set asideto hold a zero. Unfortunately, this can't be extended to more than two bytes of precision.
;FF:= FF + GG with correct carry out (CF_ is 1) mov W, G ;add low bytes add F, W mov W, <<ZERO ;shift in carry forming either 01h or 00h add W, G+1 ;add carry and high bytes add F+1, W
file: /Techref/scenix/carryx.htm, 2KB, , updated: 2004/4/5 17:32, local time: 2024/11/21 22:41,
3.145.102.18:LOG IN
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://ecomorder.com/techref/scenix/carryx.htm"> SX microcontroller CARRYX option</A> |
Did you find what you needed? |
Welcome to ecomorder.com! |
Welcome to ecomorder.com! |
.