From: "David Duffy" > Hi all, > I currently have an application where in the comms receive > handler, I test the received command byte and branch off > to other places depending on the value. As the values are > not consecutive, is there a better way to test them than just > doing the following time after time? > > ... > movf rx_cmd,w ;get the received command byte > xorlw msg_eg1 ;compare with msg_eg1 (a constant) > btfsc zero ;is it msg_eg1 ? > goto rx_eg1 ;yes, jump to that handler > ... > > Block repeats for as many test cases as I need. > It just seems ugly - is there a better/shorter way? You can improve it quite a bit like this: movf rx_cmd,w ; get received command byte xorlw msg_eg1 ; compare to msg 1 (w is zero if this is msg 1) skpnz ; (this is the same as btfsc zero) goto rx_eg1 xorlw msg_eg1^msg_eg2 ; now w is zero if this is msg 2 skpnz goto rx_eg2 xorlw msg_eg2^msg_eg3 skpnz goto rx_eg3 etc. This works because xor is its own inverse operation. -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body