A simple linear 16x comparings code would probably be
less than 100 instructions.
[/QUOTE]
The midrange PIC doesn't have a compare instruction, but there's a
trick where you XOR a literal based on the previous set of XORs to
give zero when you get the desired match.
; input port in w, return result in w, 0xFF for invalid input
convert:
xorlw 0x01
btfsc STATUS,Z
retlw 0x00
xorlw (0x3 ^ 0x01)
btfsc STATUS,Z
retlw 0x01
xorlw (0x2 ^ 0x03)
...
xorlw (0x81 ^ 080)
btfsc STATUS,Z
retlw 0x0F
retlw 0xFF
Too neat and too subtle for me Speff. This is a dedicated
uP, running just the one prog. Why not throw some simple
brute force and ignorance at the problem.
.1st Load W with 1st possible input byte.
Subtract: W - actual input byte.
Skip to .2nd if result was not zero (Z=0).
Branch if Z=1 --> Set output nibble req'd for 1st.
Clear STATUS register.
Branch back to .16th.
.2nd Load W with 2nd possible input byte.
Subtract: W - actual input byte.
Skip to .3rd if result was not zero (Z=0).
Branch if Z=1 --> Set output nibble req'd for 2nd.
Clear STATUS register.
Branch back to .1st.
Similar .3rd, .4th, up to .15th.
.16th Load W with 16th possible input byte.
Subtract: W - actual input byte.
Skip to .again if result was not zero (Z=0).
Branch if Z=1 --> Set output nibble req'd for 16th.
Clear STATUS register.
Branch back to .15th.
.again Branch back to .1st.
Branching back one place after any match focusses
each loop on the three positions centred on the
last successful match. So each 3-position loop
will be about 7 to 20 instructions.
The inputs are from microswitches, and they only need
to be visited at about 1mS intervals. That could be
a PIC with an RC clock of about 100KHz or so.