movf VALUE, W
sublw 0x20 ; is it above h'20'
btfsc STATUS,C
goto no ;false
movf VALUE, W
sublw 0x30 ; is it over h'30'
btfss STATUS,C
goto no ; false
goto yes ; true
movf VALUE, W
sublw 0x20 ; is it above h'20'
btfsc STATUS,C
goto no ;false
movf VALUE, W
sublw 0x30 ; is it over h'30'
btfss STATUS,C
goto no ; false
goto yes ; true
The method described in PICLIST, and by Agustín, is probably worth taking a closer look (if you're interested in assembly language).
Code:
;
; test for WREG value in the range of 21..30
;
addlw 255-30 ; upper limit 30 and
addlw 30-21+1 ; lower limit 21 (range 21..30)
skpc ; C=1 (in range)? yes, skip, else
goto xxxx ; branch (out of range)
;
Code:
;
; test for a pulse width of ~600-usecs ± 200-usecs
; (upper limit 800-usecs, lower limit 400-usecs)
;
movf TMR0,W ; pulse hi time (64-us ticks) |B0
addlw 255-(800/64) ; test for ~600 ± 200 usecs |B0
addlw (800-400)/64+1 ; C=1 (400..800 usec range)? |B0
skpc ; yes, skip (in range), else |B0
goto irloop ; branch (abort & start over) |B0
;
In detail, you're essentially doing a subtraction, then testing the Carry/Borrow flag <STATUS,C> to see if the number that was subtracted is greater than or less than the number it was subtracted from.
Take for instance the equation 8-7. Since 7 is less than 8, you can subtract 7 from 8 without a borrow taking place. After this equation takes place, the Carry/Borrow flag will not be set.
Now if you reverse the equation so that it's 7-8, a borrow must take place because 8 is greater than 7. In this instance, the Carry/Borrow flag will be set after subtracting 8 from 7.
The routine would go as such -
Code:
movlw <VALUE1> ;load w with value 1
sublw <VALUE2>,W ;subtract value 2 from value 1, place result in w
btfss STATUS,C ;is value 2 greater than value 1?
goto SomeLineofCode ;no, jump to SomeLineofCode
;continue with main code ;yes, continue with main code
Or you can reverse it by using "btfsc" instead so that it jumps to "SomeLineofCode" if value2 is greater and continues with main code if value2 is less.