First page Back Continue Last page Overview Graphics
Clearing Bits using Logic Instructions
Example of using an AND instruction to clear a bit:
- ldaa port_s
- anda #%11101111
- staa port_t
- We modify the above program to clear bit 2 by replacing the mask %1110 1111 with %1111 1011.
This code clears bit 4 of port A without affecting other bits in port S. The bit 4 position in the mask is zero and when ANDed, the result in the bit 4 position of accumulator A will always be zero. The other bits in accumulator A will be unaffected since they are ANDed with ones.
This technique is extremely useful when more than one bit of an output port is connected to hardware. If a fixed value were to be written to all bits of port S without regard to the current settings in port S, bits other than the one requiring modification would likely be put in states that are not desired. Your subroutine may not know what state the other bits in the port should be in, so you would not want to arbitrarily write ones or zeros to the other bits of the output port.