ARM Technical Support Knowledge Articles


Applies to: C51 C Compiler


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:

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.


Article last edited on: 2005-09-22 11:33:49

Rate this article

Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential