Hi, Start out with two dummy variables: template 000000AB mask 11111100 Do a loop where you rotate left both variables by the count of number. After the loop: var = var AND mask ; clear out location of AB var = var XOR template ; put AB into var Solution is faster with less code but more memory usage. Regards, Claudio -----Oorspronkelijk bericht----- Van: pic microcontroller discussion list [mailto:PICLIST@MITVMA.MIT.EDU]Namens Carlos Ojea Verzonden: vrijdag 19 juli 2002 10:36 Aan: PICLIST@MITVMA.MIT.EDU Onderwerp: [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