I was reading http://embeddedgurus.com/embedded-bridge/2010/03/different-bit-types-in-different-registers/, which said:
With read/write bits, firmware se
Modern processors can either set or clear bits with single instruction. However, these instructions can not both set and clear at the same time. There are instances when some of bits of an IO port must all change together and not affect other bits. As long as the sequence of read-modify-write can not be broken, there is no problem.
The situation where the r-m-w can become a problem requires three conditions.
The variable must be globally accessible such as an IO port or special function register or globally defined variable.
The global variable can be modified in a function that can be preempted.
The same global variable is modified while servicing a preemption.
The only way to resolve multiple bit modifications using a r-m-w non-atomic sequence is to protect the sequence of instructions by disabling the interrupt for the interrupt service routine that can also modify the variable or register. This is similar to digine exclusive access to resources such as LCD or serial ports.