Hi Olin. > old | new | out > -----|-------|----- > 0 | 0 | 0 > 0 | 1 | 1 > 1 | 0 | 0 > 1 | 1 | 0 !a&b=(a^b)&b movfw in ;b xorwf old_sh,W ;a^b xorwf old_sh,F ;b (stored) andwf old_sh,W movwf out WBR Dmitry. PS. I wish I could sleep less ;) Olin Lathrop wrote: > > You have 4 possible cases as shown by this truth table: > > old | new | out > -----|-------|----- > 0 | 0 | 0 > 0 | 1 | 1 > 1 | 0 | 0 > 1 | 1 | 0 > > One way (there are others) to describe what you want is OUT = (-OLD and > NEW). Here is a brute force example with bank selection left as an exercise > to the reader: > > movf portb, w ;get the NEW bits into W > movwf temp ;temp save them > andwf nold, w ;AND the NEW bits with -OLD bits > movwf out ;save OUT bits > comf temp, w ;get -NEW bits > movwf nold ;save as -OLD bits for next time > > This can probably be optimized (Dimitry? Scott?) but I'm trying to > illustrate the algorithm and show how it implements the truth table above. -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads