Shop OBEX P1 Docs P2 Docs Learn Events
waitvid in waitcnt — Parallax Forums

waitvid in waitcnt

d2rkd2rk Posts: 31
edited 2012-03-28 02:35 in Propeller 1
I've disassembled the following delay function used in program with LMM kernel:
void delay_msec(int msec) {
  waitcnt((CLKFREQ / 1000) * msec - 3932 + CNT);
}
and got such output:
00000884 <_delay_msec>:
     884:    a0bc0ff1             mov    1c <r7>, 7c4 <CNT> 
     888:    5c7c003a             jmp    e8 <__LMM_MVI_r5> 
     88c:    fffff0a4             waitvid    7e0 <CTRA>, #164 wz, wc, wr
     890:    80bc0e05             add    1c <r7>, 14 <r5> 
     894:    5c7c003a             jmp    e8 <__LMM_MVI_r5> 
     898:    00000000             nop
     89c:    a0bc0c00             mov    18 <r6>, 0 <__clkfreq> 
     8a0:    5c7c002e             jmp    b8 <__LMM_MVI_r1> 
     8a4:    000003e8             nop
     8a8:    08bc0005             rdlong    0 <__clkfreq>, 14 <r5> 
     8ac:    5cfd3e8e             jmpret    27c <__UDIVSI_ret>, #238 <__UDIVSI> 
     8b0:    a0bc0200             mov    4 <__clkmode>, 0 <__clkfreq> 
     8b4:    a0bc0006             mov    0 <__clkfreq>, 18 <r6> 
     8b8:    5cfd6eaf             jmpret    2dc <__MULSI_ret>, #2bc <__MULSI> 
     8bc:    80bc0e00             add    1c <r7>, 0 <__clkfreq> 
     8c0:    f8fc0e00             waitcnt    1c <r7>, #0 
     8c4:    a0bc220f             mov    44 <pc>, 3c <lr> 

Can anybody explain, what is waitvid doing here?

Thanks.

Comments

  • KyeKye Posts: 2,200
    edited 2012-03-27 15:23
    Its not waitvid, its -3932 in hex. The disassembler does not know the difference between code and data.

    When you see the "jmp e8 <__LMM_MVI_xx>" this means whatever that is next is data.

    Maybe a fix in the future could be applied to the dissembler to make the output more readable?
  • KyeKye Posts: 2,200
    edited 2012-03-27 15:30
    Here's a good question... why does the code generator allocate a MOV immediate value of zero in the code space??? There is no reason not to just use the mov reg, #0 form. There is no need for an immediate value expression.
  • denominatordenominator Posts: 242
    edited 2012-03-27 16:09
    Kye wrote: »
    Here's a good question... why does the code generator allocate a MOV immediate value of zero in the code space??? There is no reason not to just use the mov reg, #0 form. There is no need for an immediate value expression.

    The answer becomes apparent if you look at the assembly generated by compiling the delay_msec function with the "-Os --save-temps" flags:
    _delay_msec
            mov     r7, CNT
            jmp     #__LMM_MVI_r5
            long    -3932
            add     r7, r5
            jmp     #__LMM_MVI_r5
            long    __clkfreq
            mov     r6, r0
            jmp     #__LMM_MVI_r1
            long    1000
            rdlong  r0, r5
            call    #__UDIVSI
            mov     r1, r0
            mov     r0, r6
            call    #__MULSI
            add     r7, r0
            waitcnt r7,#0
            mov     pc,lr
    

    The disassmbler's lack of the original symbol table obscured the actual intent.
  • KyeKye Posts: 2,200
    edited 2012-03-27 16:51
    Ah, yes, its a lot easier to read now.

    Thanks, denominator!
  • d2rkd2rk Posts: 31
    edited 2012-03-28 02:35
    Thanks, Kye and denominator.
Sign In or Register to comment.