----- Original Message ----- From: "Scott Dattalo" To: Sent: Friday, July 19, 2002 9:00 AM Subject: Re: [PIC]: Code optimization > On Fri, 19 Jul 2002, Carlos Ojea wrote: > > > Hello : > > > > I want to optimize this : > > > > If number = 2 then var = xxABxxxx > > If number = 1 then var = xxxxABxx > > If number = 0 then var = xxxxxxAB > > > Scott Dattalo's answer: > If you know that 'number' can only be 0,1,2 then: > > movlw _AB_ ; assume number == 0 > > btfsc number,0 ; LSB set? > movlw (_AB_ << 2) > btfsc number,1 ; Bit 1 set? > movlw (_AB_ << 4) > > ; write the _AB_ bit pattern > > xorwf var,w ; > xorwf var,f > Er, Scott. Not such a good idea. The last two instructions are equivalent to: var = var xor w xor var which of course is the same as var = w which wipes out all the other ('xx') bits in varr Bob Ammerman RAm Systems -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body