Changing selected outputs ?
I want to change three selected output states (A24..A26). Some time back I was told the code below would alter the desired bits in the least time.
xor temp,OUTA ' combine with desired pin states
xor OUTA,temp ' set/clear for desired pin states
However, checking it w/ pencil and paper, it seems the output is not right (that is, all the remaining bits become zeros.) What am I doing wrong? Here is an example:
OUTA = 0...01_011_10...0
xor temp = 0...00_101_00...0
--------------------------------
temp = 0...01_110_10...0 1st result
xor OUTA = 0...01_011_10...0
--------------------------------
OUTA = 0...00_101_00...0 2nd result
This is what I get when I work it out on paper! I'm confused. When I first got the '2 xor's' suggestion, it was difficult to work it out, for some reason. Think I'm in that rut again. 
Comments
To change output states, you need 3 instructions and one constant:
OR OUTA,temp ' new bits are in "temp". Set desired ones XOR temp,invertBits ' all one bits in desired positions ANDN OUTA,temp ' now clear desired zeroesmov temp,outa andn temp,bitmask 'Bitmask has ones in all the bit positions to be written. or temp,newbits 'Newbits contains the new data in the positions to change, zeros elsewhere. mov outa,tempOr, if the bits to change correspond exactly to the one bits in dira,
-Phil
Mike G's scheme changes the Ones two instructions before Zeros are output; which would produce a 111 state. Phil's changes the three outputs of interest, however the change is 150-200 nsec, @ 80 MHz clock, after reading the output states. That might be a problem as other cogs could change an output during that time and it be clobbered.
As it is, presently the cog's loop is taking too long to complete vs. the external cycle it has to deal with, so I need minimal instructions to implement the control over these three bits (affecting A24..A26). (Oooh!, would Prop 2 ever be helpful here.(
xor temp,OUTA ' combine with desired pin states and temp,mask ' only retain desired bits ADDED CODE xor OUTA,temp ' set/clear for desired pin statesSo now the results would be:OUTA = 0...01_011_10...0 xor temp = 0...00_101_00...0 -------------------------------- temp = 0...01_110_10...0 1st result and temp = 0...00_111_00...0 mask off all but the 3 bits of interest -------------------------------- temp = 0...00_110_00...0 2nd result xor OUTA = 0...01_011_10...0 -------------------------------- OUTA = 0...01_101_10...0 3rd resultThis appears to solve this problem. Don't know how I talked myself into believing the original code was right. Seemed to work in PASD; but now wonder if I was also observing all the bits being outputted. Costs only one extra instruction, another 50 nsec. Don't know why I couldn't see this earlier.Your latest solution is correct.
It's only a problem if your cog's dira has bits set to one that those other cogs are outputting on. Otherwise, your cog will not alter those outputs, even if they change during your three-instruction mod of outa.
-Phil