MPASM, PIC18F65K22: Check if one number is greater than another?

Status
Not open for further replies.
T

treez

Guest
Hello,
I am coding in MPASM (microchip) for PIC18F65K22.

I have numbers contained in two registers,
One is called ana8, the other is called max_led_temp.

I wish to find out if the value in ana8 is greater than the value in max_led_temp.
Can I do this by subtracting ana8 from max_led_temp and checking if the Carry flag of the status register is set?…eg


Code ASM - [expand]
1
2
3
4
5
movf    ana8,w
bcf     STATUS,C
subwf   max_led_temp,w
btfsc   STATUS,C
goto    overtemp



(the numbers in either register may be between 0 and 255)
 
Last edited by a moderator:

yes, that is the way to do it.
There is another possible outcome you might also want to check, that the two values are equal. The Z flag will tell you that.

Brian.
 
Reactions: treez

    T

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…