My chip reads a parallel input, 8 bit, input ranging from 80 to 255. My circuit reads this and places it in a temporary file register.
Now what I want it to do is compare it to a decimal, if they match then it goes elsewhere and places a value into another file register in which the chip does other things with. I want the kind of process below
temp1 ; value read from input port.
does temp1 = 255 then goto elsewhere
if not then
does temp1 = 254 then goto elswhere2
if not then
etc, etc..
I'm not quite sure how I would do it, I thought somewhere along these lines but this seems to be long and drawn out,
Have you found PicList yet? There are lots of mostly obvious time savers there, but some are really clever. Here's link to test for whether a number is in a range:
radix dec
;
;
movf PORTB,W ; get byte from PORTB |00
addlw -(255+1) ; range check |00
addlw (255-80)+1 ; range 80..255? |00
skpc ; yes, skip, else |00
goto range_error ; |00
;
; 175 entries, one for each value 80 through 255
;
case
addwf PCL,F ; affect a jump |00
goto case80 ; |00
goto case81 ; |00
goto case82 ; |00
; ~~~~
goto case255 ; |00
The value left in WREG after a 'successful' range check is 0..175 which provides a convenient index for a table. There are some caveats associated with modifying PCL and setting up the table depending on the PIC family you're using.
Do all the "elsewheres" simply modify the delay? If so, you can use a lookup table to set the delay based on the input value, or better yet, find a formula for the delay which you can calculate.
I have put piclist in my favourites thanks to John.
Pommie that was the type of thing I were thinking of at first but I went for a table in the end, not covered this bit of programming yet but It worked out perfect.
Thanks Mike for pointing out using a table, I wasn't quite sure how they worked at first, a lot simpler than I thought. So my program is now working perfect.
NorthGuy, it is for a delay, but a little random so I couldn't use a formula unfortunately.
I misread your original question, which is not an infrequent occurrence for me to do. After re-reading it, I agree completely abut using a table. Glad you found the PicList link useful for other reasons.
What controller are you using? You may need to use high/low tables to cover the span of values + instructions that you need. A variant of that is to use a table within a table (aka double-table) described by Peter Anderson here: https://www.phanderson.com/PIC/16C84/mult_string.html
You only need one branch instruction after the test for zero instruction -
Code:
;compare, jump if equal routine
movlw temp1 ;compare received data to 255
xorlw d'255',W
btfsc STATUS,Z ;temp1 = 255?
goto elsewhere ;yes
This code will jump elsewhere if the values are equal, else it will continue with normal code flow. You can also use a call instruction instead of a goto so that the code always returns back to comparing values if you wish.
However, with that many possible values I would seriously consider doing it via a lookup table.