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 > > 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? 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 If 'number' can be 0,1,2,3 and _AB_ is not constant: movf _AB_,w btfsc number,1 swapf _AB_,W btfss number,0 goto L_LSB_IS_0 movwf temp_AB_ addwf temp_AB_,W addwf temp_AB_,W addwf temp_AB_,W L_LSB_IS_0: xorwf var,w xorwf var,f I suspect there are other optimizations that could be made if more was known about the system. Scott -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body