Shop OBEX P1 Docs P2 Docs Learn Events
Mov cnt,cnt — Parallax Forums

Mov cnt,cnt

aldoriforaldorifor Posts: 15
edited 2012-11-07 18:52 in Propeller 1
:lol:Hello,
Is there someone who can explain me what does the pasm instruction MOV CNT,CNT.:thumb:
The CNT register is a read only one, isn't it?:innocent:

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2012-11-07 05:10
    Only in the source slot of an instruction (mov cnt, cnt). Using it in the destination slot (mov cnt, cnt) will access its shadow register which is r/w. This is something you have to memorize (the same is true for par, ina and phsx).
  • Mike GMike G Posts: 2,702
    edited 2012-11-07 05:29
    I have never really understood the shadow register concept. If the following instruction is invoked, what use is the cnt shadow register if shadow cnt can not be used as a source?
    mov cnt, cnt
    

    Example?
  • kuronekokuroneko Posts: 3,623
    edited 2012-11-07 05:32
    mov     cnt, cnt
    add     cnt, #9{14} + 26
    waitcnt cnt, #0
    
    This will give you a delay of 40 cycles.

    Or this one:
    mov     cnt, cnt
    wrlong  cnt, addr
    
    writes cnt to hub (the system counter that is), same as
    mov     temp, cnt
    wrlong  temp, addr
    
  • Mike GMike G Posts: 2,702
    edited 2012-11-07 05:36
    Ah got it! Thanks
  • BeanBean Posts: 8,129
    edited 2012-11-07 05:43
    Would this also work ?
    mov cnt,#10
    loop:
      ' Code to run 10 times
    djnz cnt,#loop
    

    Bean
  • kuronekokuroneko Posts: 3,623
    edited 2012-11-07 05:45
    Bean wrote: »
    Would this also work ?
    Yes. The only disadvantage is you can't access the loop index directly.
  • aldoriforaldorifor Posts: 15
    edited 2012-11-07 06:33
    Great thanks,:smile: and forgive my poor english (I am French).

    "Only in the source slot of an instruction (mov cnt, cnt)."
    May i understand the CNT register is read only, only in the source slot of an instruction????
    "Using it in the destination slot (mov cnt, cnt) will access its shadow register which is r/w."
    Hum! how to write into the shadow register?
  • aldoriforaldorifor Posts: 15
    edited 2012-11-07 07:02
    Great thanks,:smile: and forgive my poor english (I am French).

    "Only in the source slot of an instruction (mov cnt, cnt)."
    May i understand the CNT register is read only, only in the source slot of an instruction????
    "Using it in the destination slot (mov cnt, cnt) will access its shadow register which is r/w."
    Hum! how to write into the shadow register?

    Sorry, how to read the shadow register?
  • BeanBean Posts: 8,129
    edited 2012-11-07 07:04
    You can't read it.

    But you should be able to do CMP to see if it is equal to a value, or above or below a value.

    Bean
  • tonyp12tonyp12 Posts: 1,951
    edited 2012-11-07 07:45
    The special registers have a branch (multiplex) they actually exists at two places depending if you have it on d or s location
    One is the "real" one, the other one is just like any other cog ram location.

    The read-only one can only be accessed on the "source" location of a pasm command: xxx ddd,sss
    If you write to it you are writing to ram, and the word CNT is just a reserved word that now will be a generic ram location instead.

    Writing to Hub ram with the d-field as source does not count as read-only, as the rule is d or s side.
  • aldoriforaldorifor Posts: 15
    edited 2012-11-07 08:07
    Well, i am a very beginner about pasm, but i think i understand now.
    Is the following true ?

    The running system clock counter can be read using CNT address as the source field of an instruction and not the CNT shadow register.
    An aptempt to write using CNT address as destination field of an instruction, can't write the running system clock counter but instead write to the content of the CNT shadow register. As well, using CNT address as destination field of an instruction cause the CNT shadow register to be read if the instruction used do something like "D <- D op S"

    ie : MOV CNT,CNT affect the CNT shadow register with a snapshot of the running system clock counter
    and MOV CNT, #2 affect the CNT shadow register with 2
    and also ADD CNT, #1 read the CNT shadow register (2) add 1 and store the result (3) in the CNT shadow register.
  • aldoriforaldorifor Posts: 15
    edited 2012-11-07 08:16
    "Writing to Hub ram with the d-field as source does not count as read-only, as the rule is d or s side. "

    Interresting, and what is the result of WRLONG CNT, H1 and RDLONG H2,CNT?
  • tonyp12tonyp12 Posts: 1,951
    edited 2012-11-07 08:58
    WRLONG CNT, H1....... will write the shadow to the hub location that H1 is pointing too.
    RDLONG H2,CNT......... will read hub location that CNT is pointing to (not useful, as that is ever increasing number)


    The HUB-OP WRLONG is not a xxx sss,sss command, as that does not exist.

    WRLONG is a RDLONG with NR flag set.
    and underlying HUB circuit intervene and make the "source",source writes.
  • aldoriforaldorifor Posts: 15
    edited 2012-11-07 13:00
    Hello, I'm back again.
    Tonyp12, thank for all your explanation (thank you everybody too). Now, all about "MOV CNT,CNT" is quiet clear for me.
    WRLONG CNT,H1 will write the shadow to a hub address. Thus, this is a way to read shadows registers.This let me understand some Kuruneko's examples code an its reply about Mister Bean's (sorry , it's a joke so much easy to do) DJNZ example ("Yes. The only disadvantage is you can't access the loop index directly. ")

    MERCI BEAUCOUP A VOUS TOUS

    learning alone can be sometime a great satisfaction, but more than once very hard.
  • Mark_TMark_T Posts: 1,981
    edited 2012-11-07 16:34
    tonyp12 wrote: »
    RDLONG H2,CNT......... will read hub location that CNT is pointing to (not useful, as that is ever increasing number)
    You say not useful, but I bet kuroneko has a use!!
  • tonyp12tonyp12 Posts: 1,951
    edited 2012-11-07 18:52
    >You say not useful, but I bet kuroneko has a use!!
    I have seen him using PHSA in this way, as you can get it to do 1/8 clock rate etc and also give it a start number.
Sign In or Register to comment.