Shop OBEX P1 Docs P2 Docs Learn Events
PASM command "WRLONG INA, HubAddr" won't work? — Parallax Forums

PASM command "WRLONG INA, HubAddr" won't work?

MJHanaganMJHanagan Posts: 189
edited 2013-12-31 18:12 in Propeller 1
I discovered what seems to me to be an oddity in PASM. I am trying to understand the relationship of registers DIRA, OUTA and INA in a cog compared with other running cogs as well as in cog0. I tried the following code:
CmdDone                 WRLONG  DIRA, DIRaddr
                        WRLONG  OUTA, OUTaddr
                        WRLONG  INA,  INaddr
                        
                        WRLONG  DONE, CmdAddr      'Set command variable to zero to indicate done with last command.
                         
                        JMP     #CmdWait               'Go back and wait for next command

The DIRA and OUTA registers were correctly written to the main hub memory but the INA result was all zeros.

I then tried this bit of code:
CmdDone                 WRLONG  DIRA, DIRaddr
                        WRLONG  OUTA, OUTaddr
                        mov     Tmp, INA
                        WRLONG  Tmp,  INaddr
                        
                        WRLONG  DONE, CmdAddr      'Set command variable to zero to indicate done with last command.
                         
                        JMP     #CmdWait               'Go back and wait for next command

And it worked fine.

Any idea why the WRLONG INA, INaddr command failed?

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2013-12-31 11:55
    ina can't be used in the destination field of an instruction if you want to reference the pin values. Your workaround is what's required. I think you can also do this to save using a cog register:
            mov     ina,ina
            wrlong  ina,inaddr
    

    This should copy the pins to ina's shadow register. The wrlong then writes the shadow register contents to the hub.

    -Phil
  • MJHanaganMJHanagan Posts: 189
    edited 2013-12-31 12:10
    ina can't be used in the destination field of an instruction. Your workaround is what's required.

    -Phil

    They must just be keeping with the structure rule that applies to the basic PASM command structure of: "command" "destination", "source" even though the WRBYTE, WRWORD and WRLONG commands treat the the first variable as read only. Even the Propeller Manual states that "The WR effect can not be used with WRLONG as that would change it to a RDLONG instruction.

    Thank you for the explanation!
  • jazzedjazzed Posts: 11,803
    edited 2013-12-31 12:28
    Number 2 gotcha in PASM.

    Want to guess "number" 1?
  • MJHanaganMJHanagan Posts: 189
    edited 2013-12-31 13:51
    jazzed wrote: »
    Number 2 gotcha in PASM.

    Want to guess "number" 1?

    Incorrect passing of the PAR?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2013-12-31 13:57
    MJ, jazzed gave you a "hint." :)

    -Phil
  • David BetzDavid Betz Posts: 14,516
    edited 2013-12-31 14:07
    MJ, jazzed gave you a "hint." :)

    -Phil

    Maybe
        jmp foo
    

    instead of
        jmp #foo
    
  • MJHanaganMJHanagan Posts: 189
    edited 2013-12-31 14:27
    Must be the literal value mistake: mov VarName, 1 instead of mov VarName, #1
  • Mark_TMark_T Posts: 1,981
    edited 2013-12-31 15:16
    I'd agree, forgetting a # is easy to do and results are often obscure. You get warnings if its a jump/call,
    but not if you do something like
                add     sum, 1
    
    Despite this being almost never useful... Perhaps # should have been assumed for numeric
    constants, and @1 used for the above behaviour.
  • jazzedjazzed Posts: 11,803
    edited 2013-12-31 15:33
    Missing # affects everyone. It's like having a room on the 13th floor of a hotel. Best to learn it early.

    There are valid reasons to not have # in some jmp commands though :).

    There are other common errors to avoid.

    1. Never put RES in the middle of code.
    2. Never assume ORG N sets a global start address (it sets the src/addr reference offset).
    3. Others: see Phil's Tricks & Traps document.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2013-12-31 15:36
    jazzed wrote:
    Missing # affects everyone.
    I always do a Search on JMPs and CALLs to look for missing #'s in my PASM programs. I usually find one or two, too!

    -Phil
  • David BetzDavid Betz Posts: 14,516
    edited 2013-12-31 15:52
    I always do a Search on JMPs and CALLs to look for missing #'s in my PASM programs. I usually find one or two, too!

    -Phil
    Chip has been talking about eliminating the need for # in jmp instructions for PASM2. I'm not sure if he's decided to go ahead wtih that or not though.
  • MJHanaganMJHanagan Posts: 189
    edited 2013-12-31 16:07
    ina can't be used in the destination field of an instruction if you want to reference the pin values. Your workaround is what's required. I think you can also do this to save using a cog register:
            mov     ina,ina
            wrlong  ina,inaddr
    

    This should copy the pins to ina's shadow register. The wrlong then writes the shadow register contents to the hub.

    -Phil

    Yes, the mov INA, INA followed by WRLONG INA, INaddr does work. So now I'm really confused. I though INA was read-only.
  • jazzedjazzed Posts: 11,803
    edited 2013-12-31 16:16
    MJHanagan wrote: »
    Yes, the mov INA, INA followed by WRLONG INA, INaddr does work. So now I'm really confused. I though INA was read-only.
    When INA is a source (mov destination, source), you read the value on INA. When INA is a destination (wrlong ina, address), you are reading the "shadow" value put there by mov ina, ina. This is a more advanced concept than necessary, but if you need more register space for some reason, it's good to know about it.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2013-12-31 16:16
    There are actually two ina "registers": the pins themselves and a "shadow register" at the same address. When you use ina in the destination field, it refers to the shadow register, not the pins.

    -Phil
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2013-12-31 16:25
    David Betz wrote:
    Chip has been talking about eliminating the need for # in jmp instructions for PASM2.
    I wouldn't mind seeing that. Make jmp dst,src refer to an immediate value and jmp dest,@src refer to the contents of src.

    It's probably too late to deal with => and =< or to swap -> (the one with the minus sign; that's a rotate) with ~> (the one with the rotary-looking tilde; that's a sign-extended shift) though. And I think the precedence rules should align more with those of other languages, although I like Spin's better.

    -Phil
  • jazzedjazzed Posts: 11,803
    edited 2013-12-31 16:44
    And I think the precedence rules should align more with those of other languages, although I like Spin's better.

    This is Phil??? I'll take it even with the caveat! :)

    Happy New Year!
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2013-12-31 18:12
    jazzed wrote:
    This is Phil??? I'll take it even with the caveat!
    It's gotten to the point that I have to look up the precedence rules for both Spin and Perl/C every time I switch from one to the other. Changing Spin's to conform is just the path of less resistance. :)

    Happy New Year to you, and everyone else on the forum! 2014: the year of the P2!

    petoskey-fireworks.jpg

    -Phil
Sign In or Register to comment.