Hi folks, I need to subtract two registers. They both vary up and down, but I'm only interested when one is up above the other, how do I set up this...?
I'm thinking of something like this:
subwf ADDR,W ;sub ADDR from W put result in W
btf STATUS,DC ; to see if it's negative
btf STATUS,Z ;to see if it's zero
goto next
The subtract instructions on a pic work in a rather non intuative way. Subwf does not subtract the file from W but the other way around (I see you know this already). Same with sublw and so the mnemonic is even wrong and should be Subtract W from Literal.
Anyway, with this in mind, if W contains (random number) 48 and ADDR contains 47 then 47-48 is calculated. This results in -1 and so the Carry flag is set (not the Digit Carry as you have above). You also want to include the case where both are the same and so you need an additional check.
Something like,
Code:
subwf ADDR,W
btfsc STATUS,Z ;were they equal
goto WasLTE ;yes
btfsc STATUS,C ;was it less than
goto WasLTE ;yes
goto next
WasLTE ;will only get to here is ADDR was less than or equal to W
It's OK I don't mind if you did, it was a joke anyway.
I have a good grasp of logic, and math, but do lack the practical experience, and the patience I have to admit. I find programming tedious and one of those things that will fall by the way side when we design programs to write programs so that writing a program can be done by anyone with an idea. I also know that a lot of these routines have been done already and if I knew how to use a more advanced tool like a linker, I could just pull the routines and link them, and then I would not have to go through the bean counting.
I used the debugger to step through the program and follow the progress, but there are still a lot of things in there I have yet to discover. One of these being the linker.