Shop OBEX P1 Docs P2 Docs Learn Events
[resolved] PHSx read-modify-write — Parallax Forums

[resolved] PHSx read-modify-write

kuronekokuroneko Posts: 3,623
edited 2009-06-04 12:59 in Propeller 1
The Propeller Manual said...
Note that in Propeller Assembly, the PHSA and PHSB registers cannot be used in a read-modify-write operation in the destination field of an instruction. Instead, separate read, modify, and write operations (instructions) must be performed.
From that I gather

mov     phsa, #8

mov     reg, phsa     ' read
add     reg, #4       ' modify
mov     phsa, reg     ' write

wrlong  phsa, somewhere


is the way to go, phsa will be 12. So far so good. However ...

mov     phsa, #8

add     phsa, #4      ' read-modify-write

wrlong  phsa, somewhere


gives me the very same result (12).

So where does the cannot be used bit come into it? Does it only apply when used concurrently with an active counter? I'm using the wrong example in active code and it works so I'm slightly confused.

Any help is appreciated.

Post Edited (kuroneko) : 6/4/2009 1:02:26 PM GMT

Comments

  • MagIO2MagIO2 Posts: 2,243
    edited 2009-06-04 12:43
    Good guess!
    Datasheed said...
    Beware that doing a read-modify-write instruction on PHS, like "[font=Parallax,Parallax size=2][font=Parallax,Parallax size=2]ADD PHSA, #1[/font][/font]", will cause the last-written value to be used as the destination operand input, rather than the current accumulation.
    PHSA actually holds two values. The value in the shadow RAM and the value in the physical register used for the count. If you do a write it writes in both registers (mov). If you use PHSA as source it uses the physical counter. If you have a read modify write instruction using PHSA as destination, PHSA is read from the shadow RAM. The shadow RAM is not updated in counter-mode.

    So, if you have the mov PHSA, #8 and then a lot of counts in between and then do the add PHSA, #4 it will still be 12.

    Currently I'm trying to find an explanation as well - not knowing it for sure.
  • TubularTubular Posts: 4,706
    edited 2009-06-04 12:46
    I'm no expert, but this thread may help a bit
    http://forums.parallax.com/showthread.php?p=742749

    There was another thread too, I'll see if I can find it

    tubular
  • kuronekokuroneko Posts: 3,623
    edited 2009-06-04 12:59
    Thanks for the link. So all it boils down to is, it's OK to do it when you don't count [noparse]:)[/noparse]
Sign In or Register to comment.