^ is exclusive-or 0 ^ 0 = 0 0 ^ 1 = 1 1 ^ 0 = 1 1 ^ 1 = 0 This has the special property that A ^ B ^ B == A In other words, if I exclusive-or an input value (A above) twice with the same value (B above), I get the original value back. Bob Ammerman RAm Systems ----- Original Message ----- From: "David Duffy" To: Sent: Tuesday, November 06, 2001 7:45 PM Subject: Re: [PIC]: Testing with non-consecutive values > > > 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? > > Bob replied: > >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. > > This gets me 1 less instruction per test. (except 1st one) > Call me a dummy but what's the ^ operator ? > The only other option is a table to jump to the required places > but this would only be worth it if you had a lot of commands. > It would make adding extra commands very easy though. > Regards... > > -- > http://www.piclist.com#nomail Going offline? Don't AutoReply us! > email listserv@mitvma.mit.edu with SET PICList DIGEST in the body > > -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body