Shop OBEX P1 Docs P2 Docs Learn Events
Assembly programming problem with CNT — Parallax Forums

Assembly programming problem with CNT

HGPLHGPL Posts: 15
edited 2007-11-06 18:38 in Propeller 1
Hi,
I worry about the code below: confused.gifconfused.gifconfused.gif

                        mov     wcol,#1
                        shl     wcol,#28
...
                        call    #waitcol                   or       call #waitcol2
...
waitcol2
                        mov     tnextcol,cnt
                        add     tnextcol,wcol                        
                        cmp     cnt,tnextcol wc   'c=1; cnt < tnextcol
                 if_c   jmp     waitcol2
waitcol2_RET            ret


waitcol                 
                        mov     clk,cnt
                        add     clk,wcol
                        waitcnt clk,wcol
waitcol_ret             ret



The waitcol is working. The waitcol2 not working...
I think make the fixrate wait with a pin verifying capability, and the waitcnt not good here...

Anybody know help for me...?

thanks, Gabor

Post Edited (HGPL) : 11/6/2007 4:18:41 PM GMT

Comments

  • deSilvadeSilva Posts: 2,967
    edited 2007-11-06 16:14
    waitcol2
           mov   tnextcol, cnt
           add   tnextcol, wcol
           cmp   cnt,      tnextcol wc    'c=1; cnt < tnextcol
      if_c jmp   waitcol2
    waitcol2_RET
           ret
    



    (1) JMP #waitcol2B
    (2) Set the label waitcol2B before the CMP; you have I fine moving target with your original code smile.gif
  • HGPLHGPL Posts: 15
    edited 2007-11-06 16:32
    yeah.gif
    Very thanks... [noparse]:)[/noparse] last hour was very poor for me...
    HVALA
    The # is a very high blame... [noparse]:)[/noparse]

    but... [noparse]:)[/noparse]

    'first column delay init 
                            mov     wcol,#1
                            shl     wcol,#19
                            mov     tnextcol,cnt
                            add     tnextcol,wcol
    ...
                            call    #waitcol2
    ...
    waitcol2
                            cmp     cnt,tnextcol wc   'c=1; cnt < nextcnt
                     if_c   jmp     #waitcol2                 
                            mov     tnextcol,cnt
                            add     tnextcol,wcol                                         
    waitcol2_RET            ret
    
    
    


    ... and not working yet...

    Post Edited (HGPL) : 11/6/2007 4:37:53 PM GMT
  • HGPLHGPL Posts: 15
    edited 2007-11-06 16:40
    huh... The newest solution is below...
    It is working, but I don't know why need the T1 temporarily variable...
    Is CNT not working with CMP command?
    waitcol2
                            mov     t1,cnt
                            cmp     t1,tnextcol wc   'c=1; cnt < nextcnt
                     if_c   jmp     #waitcol2
                     
                            mov     tnextcol,t1
                            add     tnextcol,wcol                        
                     
    waitcol2_RET            ret
    
    
  • deSilvadeSilva Posts: 2,967
    edited 2007-11-06 16:53
    Sorry, I overlooked it!

    The rule is: Never use a "special register" at the DEST operand unless you exactly know what you are doing..

    The reason: You will not read:
    - CNT
    - INA
    - PAR
    - PHSA
    - PHSB

    as expected!
    Rather you will read what you last have written to it. This is well know as "The Behaviour Of The Shadow Registers" smile.gif

    You can fix it in your second example by just reversing CNT and TNEXTCOL and jumping IF_NC

    Another note: Once every 40 to 50 seconds your program will fail, when the CNT overflows from $FFFF_FFFF to $0
  • HGPLHGPL Posts: 15
    edited 2007-11-06 16:58
    Very Thanks!
    I will read deep the documentation [noparse]:)[/noparse] thanks.

    My setup is _CLKMODE = RCFAST
    The fail wait about 6 minutes and i will correct the code but this mistake not matter for my app.

    thanks
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2007-11-06 17:29
    HGPL,
    You can avoid using the temp variable 't1' if you use cmpsub instead of cmp
    waitcol2
                            cmpsub  tnextcol, cnt    wc, [color=#0]nr[/color]   'c=1 if tnextcnt is greater than or equal to cnt
                     if_c   jmp     #waitcol2
                     
                            mov     tnextcol, cnt
                            add     tnextcol, wcol                        
                     
    waitcol2_RET            ret
    
    



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 11/7/2007 7:55:08 PM GMT
  • HGPLHGPL Posts: 15
    edited 2007-11-06 17:45
    thanks ,

    but this last code is not working...
    I read the CMPSUB doc, and I think the code is ok, but the CNT usage is not working with this command...

    Post Edited (HGPL) : 11/6/2007 6:06:27 PM GMT
  • deSilvadeSilva Posts: 2,967
    edited 2007-11-06 18:19
    Don't get confused!

    (1) You have to read the "Erratum" www.parallax.com/dl/docs/prod/prop/PMv1.0Supplement-v1.3.pdf

    The description of the CMPSUB instruction is not only absolutely confusing in the Manual, it is WRONG!

    (2) You don't need CMPSUB! Your program will work fine, when you just reverse the operands of CMP and JUMP if NC, as I described above...

    BTW: The Eratum 1.3 now contains detailed hints wrt the "Shadow Registers"

    Edited...

    Post Edited (deSilva) : 11/6/2007 11:09:41 PM GMT
  • HGPLHGPL Posts: 15
    edited 2007-11-06 18:38
    thanks ok
Sign In or Register to comment.