|
16 bit math on PIC
I've been racking my brain on this for hours and I'm starting to get a headache.
I have a 12F683. My program (written in assembly) has gotten to the point where there is a 16 bit number somewhere. One byte is the upper 8 bits and the other byte is the lower 8 bits. Now the problem is that I need to do some math with this number. The first step is to subtract 2000 (decimal) from it. If the number is less than 2000, it either needs to leave it at 0 or I need some way of determining that it has become negative. If I can get that part, I should be able to figure out the rest on my own.
I thought of simply subtracting 7 from the upper byte then subtracting 215 from the lower byte but that presents all sorts of carry issues if the lower byte is less than 215. It seems that many of the mathematical instructions on the PIC are designed for signed bytes. This is trouble for the lower byte that needs to remain unsigned.
I tried Google, but there doesn't seem to be much info on doing multibyte math.
__________________
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GE/S/P a-- e y-- r-- s:++ d+ h! X+++
t++ C+ P+ L++ E W++ w M-- V? PS+ PE+
5- R-- tv+ b+ DI+++ D- G
------END GEEK CODE BLOCK------
|