> > > Puzzle N2> Is required to load any file REGister with value = VALUE , > > > but W register haven't be changed after load is over . > > > > MOVWF reg > > XORLW VALUE > > XORWF reg,f > > XORWF reg,W > I've another similar solution... > > XORLW VALUE > MOVWF REG > XORLW VALUE > XORWF REG,F Depending upon /Value/, it may be possible to do the job in 1 to 5 cycles without altering W _or_ the flags (useful perhaps in an ISR, since saving context is such a pain). If the old value in the f-register is known, then any change may be done in 0 to 4 cycles (zero of course being if you want to "change" the register to its existing value). Here are some of the ways of setting a register in very few instructions: [1] Set to zero: the obvious one... clrf reg [2] Set to a power of two. Also pretty obvious... clrf reg bsf reg,bit [3] Set to 255. Still pretty obvious, but for one slight detail... clrf reg decfsz reg ; Note: next instruction will NEVER be skipped. ; "decf" would affect flags. [4] Right-aligned group of bits set [e.g. bits 0-5]... clrf reg bsf reg,6 decfsz reg [5] Left-aligned group of bits set [e.g. bits 4-7]... clrf reg decfsz reg bcf reg,4 incfsz reg [6] Occasionally-useful method: [e.g. for %11110001] clrf reg bsf reg,5 decfsz reg swapf reg [7] General method: 2-4 bits set clrf reg bsf reg,bit1 bsf reg,bit2 bsf reg,bit3 [if needed] bsf reg,bit4 [if needed] [8] General method: 5-7 bits set: clrf reg decfsz reg bcf reg,unbit1 bcf reg,unbit2 [if needed] bcf reg,unbit3 [if needed] Slightly more than half of the possible values from 0-255 can be done in four or fewer cycles using one of the above methods; the remainder will take five. As far as I can tell there are no methods shorter than the above which do not affect flags or W; can anyone find any potentially-use- ful cases I missed?