Assuming: number is never anything but 2, 1 or 0 AB is constant and in this case = 01 Here is the result: movlw b'00000001' ; assume number == 0 btfsc number,0 ; is number == 1? movlw b'00000100' ; yes btfsc number,1 ; is number == 2? movlw b'00010000' ; yes iorwf var,f ; set 'B' bit movwf temp ; save the 'B' mask addwf temp,w ; turn it into the 'A' mask xorlw 0xFF ; complement it andwf var,f ; turn off the 'A' bit And that is less than the proverbial 12 instructions and isochronous to boot. I am sure someone will do better. Bob Ammerman RAm Systems ----- Original Message ----- From: "Carlos Ojea" To: Sent: Friday, July 19, 2002 4:35 AM Subject: [PIC]: Code optimization > Hello : > > I want to optimize this : > > If number = 2 then var = xxABxxxx > If number = 1 then var = xxxxABxx > If number = 0 then var = xxxxxxAB > > I wrote this large code (assuming A is '0' and B is '1'): > > movlw 0x02 > BANKSEL number > xorwf number, W > bz n2 ; number is 2, so branch to n2 > movlw 0x01 > xorwf number, W > bz n1 ; number is 1, branch to n1 > bcf var, 0x01 ;number is 0, write xxxxxxAx > bsf var, 0x00 ; write xxxxxxxB > goto finish > > > n2 > bcf var, 0x05 ; write xxAxxxxx > bsf var, 0x04 ; write xxxBxxxx > goto finish > > > n1 > bcf var, 0x03 ; write xxxxAxxx > bsf var, 0x02 ; write xxxxxBxx > > > finish > ... > ... > ... > more code > ... > ... > ... > > > Anyone knows how to optimize that? > > -- > 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