C51: READ-MODIFY-WRITE REGISTERS
Information in this article applies to:
I keep hearing about READ-MODIFY-WRITE registers and I don't understand what this means?
READ-MODIFY-WRITE refers to the technique used to implement an assembly instruction and is typically used by the bitwise operations (AND, OR, XOR). For example, the following instruction:
reads the value of the P1 latch (not the input pins), modifys the value read--it performs a bitwise OR (with 0x01)--, and writes the new value back into the P1 latch.
There are usually no side-effects of READ-MODIFY-WRITE instructions when accessing registers that have the same values when read or when written (because they act like RAM). However, READ-MODIFY-WRITE instructions can cause problems when the register being accessed is write-only or reads a different value than what was written.
A characteristic of the I/O ports of the 8051 is that the value you write may not be the value you read (since reading the port returns the state of the port pins). However, these registers are specially treated for READ-MODIFY-WRITE instructions and instructions like ORL P1,#01 read the port latch (the previously written P1 value) instead of the port pins.
You should carefully check the registers of a specific device to be certain how they behave with respect to the READ-MODIFY-WRITE instructions.
Last Reviewed: Thursday, September 22, 2005
of your data.