Keil Logo

C51: READ-MODIFY-WRITE Registers


Information in this article applies to:

  • C51 All Versions

QUESTION

I keep hearing about READ-MODIFY-WRITE registers and I don't understand what this means?

ANSWER

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:

ORL     P1,#01h

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.

MORE INFORMATION

  • Refer to ANL in the 8051 Instruction Set Manual.
  • Refer to ORL in the 8051 Instruction Set Manual.
  • Refer to XRL in the 8051 Instruction Set Manual.

Last Reviewed: Thursday, February 25, 2021


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.