Shop OBEX P1 Docs P2 Docs Learn Events
How to replace 7 nop? — Parallax Forums

How to replace 7 nop?

jmspaggijmspaggi Posts: 629
edited 2010-09-12 06:27 in Propeller 1
Hi all,

In a PASM method I have 7 NOP that I would like to replace by something cleaner.

They are used to create a delay.
:aWSBits                test    aData,#$80 wz
                if_z    andn    outa,mskSI
                if_nz   or      outa,mskSI
                        shl     aData,#1
                        nop                             ' Need to wait for 2 CLKI = 83 nano-seconds
                        nop                             ' nop = 4 prop cycles = 50 nano-seconds
                        nop                             ' So 2 nops might be enought, but seems not.
                        nop
                        nop
                        nop
                        nop
                        or      outa,mskSCLK
                        nop
                        nop
                        nop                             ' So 2 nops might be enought, but seems not.
                        nop
                        nop
                        nop
                        nop
                        andn    outa,mskSCLK

This is not my code ;) I got it for the VLSI ogg player chipset.

Initialy, there was 3 NOPs. But I figured that some songs need more, so I moved to 4, 5, and so on. Now, look like with 7 NOPs it's slow enought so each song has the time to play.

7 NOP = 28 cycles = 350ns.
Do I have a way to use WAITCNT for that?

Like:
  mov  t1, 28  ' 4 cycles.
  add t1, cnt ' 4 cycles.
  waitcnt t1, #0

My questions: Is that cleaner than 7 nop? Will I not miss the clock because I'm not fast enought?

Thanks,

JM

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-09-11 11:09
    For really short delays, you might be better off using a DJNZ instruction. These take 4 cycles when the jump is successful and 8 when it fails:
    mov    t1,#5
    :delay  djnz   t1,#:delay
    
    Including the mov, this provides 7 x 4 clock cycles' delay.
  • jmspaggijmspaggi Posts: 629
    edited 2010-09-11 11:43
    4 cycles for the mov, then 4 times 4 cycles for the djnz and the last one is 8. So 1+4+2 = 7.

    Got it!

    Minimum is mov + djnz = 4 + 8. So 3 cycles.

    Thanks! Will look cleaner than adding NOPs ;)

    JM
  • HarleyHarley Posts: 997
    edited 2010-09-11 12:11
    And will take less lines in the source when you print it and look at it on screen! Neater, less clutter, cleaner comment-wise.
    Will look cleaner than adding NOPs
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2010-09-11 15:44
    You could do this... :smilewinkgrin:
    DAT
    
    :aWSBits                test    aData,#$80 wz
                    if_z    andn    outa,mskSI
                    if_nz   or      outa,mskSI
                            shl     aData,#1
                            long    0,0,0,0,0,0,0        ' Need to wait for 2 CLKI = 83 nano-seconds
                                                         ' nop = 4 prop cycles = 50 nano-seconds
                                                         ' So 2 nops might be enought, but seems not.
                            or      outa,mskSCLK
                            long    0,0,0,0,0,0,0        ' So 2 nops might be enought, but seems not.
                            andn    outa,mskSCLK
    

    ...each Zero after the long evaluates to a NOP instruction.
  • kuronekokuroneko Posts: 3,623
    edited 2010-09-11 16:12
    @Beau: In this case
    long    0[7]
    
    may be even cleaner. Anyway, I don't see anything wrong with a waitcnt (as long as the minimum delay isn't an issue). A djnz may take less space but active delays feel wrong.
    mov     cnt, cnt
    add     cnt, #9 + n
    waitcnt cnt, #0
    

    This will delay for 14 + n cycles.

    FWIW, the initial example (assuming #28) is waiting for too long (14 + 28 - 5) anyway.
    mov     cnt, #5 + [COLOR="Red"]14[/COLOR]
    add     cnt, cnt
    waitcnt cnt, #0
    
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2010-09-11 17:19
    kuroneko,

    :lol: good one!... I just briefly looked at the DAT definition in the Manual and didn't think that (meaning the square brackets) would have been possible in Pasm, but I just tried it and it worked just fine.
  • kuronekokuroneko Posts: 3,623
    edited 2010-09-11 18:05
    I just briefly looked at the DAT definition in the Manual and didn't think that (meaning the square brackets) would have been possible in Pasm, but I just tried it and it worked just fine.

    Apologies for getting slightly OT. Repeating large numbers of instructions can also be done like this:
    CON
      mult_pin = 0
    
      add_frqa_frqa = $80BFF5FA     ' add frqa, frqa
      [COLOR="Red"]ror_outa_imm1[/COLOR] = $20FFE801     ' ror outa, #1
    
      zero = $1FF   ' vscl
    
    DAT
            ...
            xor     outa, minus1            ' +20   OR logic, 1: disabled
    
            long    [COLOR="Red"]ror_outa_imm1[15][/COLOR]       '
            long    [COLOR="Red"]ror_outa_imm1[16][/COLOR]       ' send out remaining gate bits
    
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-09-11 19:07
    This sort of begs the question of why something like this was never implemented in the assembler:
            ror     outa,#1 [15]
    
    or even:
    (       movs    acc,ina
            shl     acc,#8) [4]
    
    'Makes perfect sense.

    But, in any event, the rep instruction in the Prop II will spare us all that.

    -Phil
  • jmspaggijmspaggi Posts: 629
    edited 2010-09-12 06:27
    Wow.

    Folks, you are crazy! ;)

    Anyway, I now know a bit more in PASM ;)

    I will probably use the long 0[7]. I found it nice. I will just have to comment it a lot.

    Thanks all!

    JM
Sign In or Register to comment.