salamah99
Newbie level 5
Hi All, I got the following code to subtract 2-byte numbers in pic 16f877a assembly
"
SUB16 MACRO DST, SRC
MOVF (SRC),W ; Get low byte of subtrahend
SUBWF (DST),F ; Subtract DST(low) - SRC(low)
MOVF (SRC)+1,W ; Now get high byte of subtrahend
BTFSS STATUS,C ; If there was a borrow, rather than
INCF (SRC)+1,W ; decrement high byte of dst we inc src
SUBWF (DST)+1,F ; Subtract the high byte and we're done
ENDM
"
the code works correctly until it reaches a borrow, since i tried to subtract 00005 from 65535 in a loop (doing a division), i was tracking the subtraction by printing each value to LCD
when program reaches 65280 (0xFF00) , the result of subtraction goes to 65531, I am trying to find the trick and solve it in the above code. can anybody help ?
"
SUB16 MACRO DST, SRC
MOVF (SRC),W ; Get low byte of subtrahend
SUBWF (DST),F ; Subtract DST(low) - SRC(low)
MOVF (SRC)+1,W ; Now get high byte of subtrahend
BTFSS STATUS,C ; If there was a borrow, rather than
INCF (SRC)+1,W ; decrement high byte of dst we inc src
SUBWF (DST)+1,F ; Subtract the high byte and we're done
ENDM
"
the code works correctly until it reaches a borrow, since i tried to subtract 00005 from 65535 in a loop (doing a division), i was tracking the subtraction by printing each value to LCD
when program reaches 65280 (0xFF00) , the result of subtraction goes to 65531, I am trying to find the trick and solve it in the above code. can anybody help ?