Searching \ for 'Read Modify Write commands' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=read+modify+write
Search entire site for: 'Read Modify Write commands'.

Truncated match.
PICList Thread
'Read Modify Write commands'
1996\05\17@085614 by 9 NPL, 2227

flavicon
face
   The data book states that BCF,BSF, etc are read modify write
instructions and care has to be taken with using these instruction on a port
- The question is, what is the 'etc' instructions they are on about.
I can see that any instruction that is set to write back to 'f' where 'f' is
a port, could come under this title, but are there any others??

   steve

1996\05\17@122954 by John Payson

flavicon
face
>     The data book states that BCF,BSF, etc are read modify write
> instructions and care has to be taken with using these instruction on a port
> - The question is, what is the 'etc' instructions they are on about.
> I can see that any instruction that is set to write back to 'f' where 'f' is
> a port, could come under this title, but are there any others??

Any instruction (other than MOVWF and CLRF) which writes to a port will read
it first and use the read value in computing what to write there.  While BSF
and BCF are the most common read/modify/write instructions used on port pins,
all instructions other than MOVWF which write the port pins will have the
same caveats.

Note, btw, that at least on the 16C84 (and probably on other members of the
16Cxx family) even the movwf and clrf instructions will read an address before
they write to it.  This is usually not a problem, but if an address has side-
effects on a read (such as the port B compare latches) those side-effects will
also be triggered on a write.

1996\05\20@061029 by 9 NPL, 2227

flavicon
face
John Payson <spam_OUTsupercatTakeThisOuTspammcs.com> wrote:-
>Note btw, that at least on the 16C84 (and probably on other members of the
>16Cxx family) even the movwf and clrf instructions will read an address
>before they write to it.  This is usually not a problem, but if an address
>has side-effects on a read (such as the port B compare latches) those
>side-effects will also be triggered on a write.

Thanks John - That little BTW just saved me a week or two of hair pulling.
It also stuck a large spanner in the proverbial, for my latest project :-(

   The idea was to use PB4 and 7 to bidirectional read / write two serial
data signals, with INT reading a common clock (all on interrupts). I was
also going to use PB1-3 as LCD control signals (only writing to them was
required, so I assumed this would not interfere with the portb change
interrupt).

   Does anybody know if this 'feature' does extend to the 16C62X and
others? If so, I'll just have to run the LCD serially, as various web pages
show. (but how you get at the LCD busy flag, I don't know!)

   Steve

1996\05\20@110548 by Benjamin Tober

flavicon
face
{Quote hidden}

It sure does.  On all PICs (and most other processors for that matter), any
instruction that writes to a memory location writes to at least whole bytes
(or, on processors with wider data buses, whole words, double words, quad
words, etc...).  When an instruction exists which must "change" some bits
of a location, it has to read the old contents of the location, modify the
value to be written, and then write back the whole byte.  That is, any
instruction which changes the contents of a location in a way which
depends on the current contents of that location is a
read-modify-write instruction.  These instructions must all be used with
care on ports and control registers for on-board peripheral devices.
-ben
--
Benjamin A. Tober -                    -WBRS FM - 100.1Mhz in Waltham,Ma.
email: toberspamKILLspamcs.brandeis.edu           -FreeLiveMusic Four Times Weekly
"Are you a truck?"                     -24hr/day all-genre diversity

1996\05\20@165843 by John Payson

flavicon
face
> It sure does.  On all PICs (and most other processors for that matter), any
> instruction that writes to a memory location writes to at least whole bytes
> (or, on processors with wider data buses, whole words, double words, quad
> words, etc...).  When an instruction exists which must "change" some bits
> of a location, it has to read the old contents of the location, modify the
> value to be written, and then write back the whole byte.  That is, any
> instruction which changes the contents of a location in a way which
> depends on the current contents of that location is a
> read-modify-write instruction.  These instructions must all be used with
> care on ports and control registers for on-board peripheral devices.

There are two issues here, which need to be considered seperately for any
CPU:

[1] Read data from a port may not always match data that should be written
   to keep the same "state".  For example, if a port pin is trying to
   output a low signal but external capacitance is pulling it up above
   the switching threshhold, it will read back as a "1"; if its read-back
   value is sent to the port, it will change the port's value.  There are
   five approaches I've seen to this issue:

  (a) Ports are set to be input or output; reading a port which is
      configured as output will read back the STORED value, regardless
      of the voltage on the pin. (e.g. 6522 VIA chip)

  (b) Ports are set to be input or output; reading a port which is
      configured as output will read back the voltage on the pin, which
      will hopefully--but not always--match the output value. (PIC)

  (c) Ports are open-collector output, but the system knows that certain
      instructions are read/modify/write; these instructions will always
      read the stored value, regardless of what's on the pins. (8x51)

  (d) Ports are open-collector output; reading a port will show what's
      on the pins (/AutoFeedXT etc. on many PC printer ports)

  (e) Reading a port outputs a value independent of the port function (may
      typically be $00 or $FF).  Used in cases where hardware designers
      did not want the expense or complexity of readback hardware.

[2] The mere act of reading a port may have side-effects, even when the
   value read back is not taken into account.  For example, on the PIC16C84
   writing to port B always causes a read first.  As a consequence, it will
   clear any pending port B interrupt.  Note that this restriction applies,
   on the PIC, even to the movwf instruction which does not do anything with
   the read-from-port value.

Note that on the PIC #2 isn't usually too bad.  On the 6502, though, it could
at times be a major stumper.  For example, one common trick on the 6502 for
skipping a 2-byte instruction is to put a $2C before it.  Since $2C is the
opcode for "BIT", which does nothing except read a memory location and update
the flags based upon it, it's very useful as a 3-byte "pseudo-nop".  The
gotcha is that a memory location, determined by the next instruction, will be
read.  For example, if the instruction skipped were
 "lda #$C0"
putting a $2C before it would result in a "BIT $C0A9" being executed; this
could cause some wierd effects and be hard to diagnose.

1996\05\20@193600 by fastfwd

face
flavicon
face
John Payson <.....PICLISTKILLspamspam.....MITVMA.MIT.EDU> wrote:

> Note that on the PIC #2 isn't usually too bad.  On the 6502, though,
> it could at times be a major stumper.  For example, one common trick
> on the 6502 for skipping a 2-byte instruction is to put a $2C before
> it.  Since $2C is the opcode for "BIT", which does nothing except
> read a memory location and update the flags based upon it, it's very
> useful as a 3-byte "pseudo-nop".  The gotcha is that a memory
> location, determined by the next instruction, will be read.  For
> example, if the instruction skipped were
>   "lda #$C0"
> putting a $2C before it would result in a "BIT $C0A9" being
> executed; this could cause some wierd effects and be hard to
> diagnose.

Guess you did a lot of Apple-II programming back in the old days,
huh?

-Andy

Andrew Warren - EraseMEfastfwdspam_OUTspamTakeThisOuTix.netcom.com
Fast Forward Engineering, Vista, California
http://www.geocities.com/SiliconValley/2499

More... (looser matching)
- Last day of these posts
- In 1996 , 1997 only
- Today
- New search...