Shop OBEX P1 Docs P2 Docs Learn Events
cnt question — Parallax Forums

cnt question

With an instruction like:

wrlong cnt par

Will the value of cnt transferred be the value
when the instruction is encountered
or when the transfer actually takes place?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2016-12-29 05:09
    I'll let someone else give you the definitive answer, but instructions generally consist of 4 cycles, each one clock cycle long. The hub instructions stall waiting for the hub to be available which adds additional cycles, but the instruction is fetched and decoded, then the source operand (cnt) is fetched, then the destination operand is fetched and the instruction is actually executed. In your case, the value of CNT used as source in a WRLONG is that fetched in the second instruction phase. I could be off, but I think this is the case. There's an application note that goes into more detail, but I don't have a link to it.
  • Neither, if you mean the system counter value. With cnt in the destination field you're using the shadow register.

    Page 9 of the Propeller data sheet describes the execution stages.
  • tonyp12tonyp12 Posts: 1,951
    edited 2016-12-29 21:57
    So your instruction above would write shadow-cnt cog value to HUB address long.

    Shadow: a register location on the <Left side> of a instructions, so it's not a <destination rule> as for WRLONG it may look like you're pointing to source-side-cnt
    that hardware will not update the "left side version of cnt" and should just be treated as free ram.

    You could do a mov cnt,cnt first if you want to send the cnt value.


  • K2K2 Posts: 693
    Thanks for the insightful answers! Mike and page 9 of the datasheet relieved my mind regarding the initial question.

    The shadow register matter is a new complication. Since wrlong operates differently than other instructions, in the sense that data flows l-to-r in its specific case, I figured cnt could be used where normally a destination is specified. (I remember some interesting discussions involving shadow registers years ago. When I have time I'll look up those old posts and try to educate myself regarding that whole business.)

    Anyway, I ended up doing as tony suggests: I saved the instantaneous value of cnt to a local register and then transferred it to HUB with a second instruction. Works great. Still leaves me wondering if I could have coded it better.
  • Cluso99Cluso99 Posts: 18,069
    Safer to just do a mov reg,cnt followed by a wrlong reg,par
  • Cluso99 wrote: »
    Safer to just do a mov reg,cnt followed by a wrlong reg,par
    Less confusing, anyway.

  • tonyp12tonyp12 Posts: 1,951
    edited 2017-01-01 21:28
    As shadow reg (left side) is free ram that normally don't get used.

    These below are both the same:
    mov CNT,CNT 'copy value to shadow.
    mov $1F1,CNT 'copy value to shadow.

    The intented use of CNT is read-only, right-side/source-side only.
    so the cogs hardware overrides the cogs local ram address of $1F1 when it's on the right side/source side and reach out the global system counter.

    It's not hard to imagine that the left-side shadow-register just sit there dormant.
    WRLONG uses it as "source" but the hardware don't override left side use of $1F1
Sign In or Register to comment.