Shop OBEX P1 Docs P2 Docs Learn Events
Use of long, word, byte, res in inline assembly Solved. RET needed! — Parallax Forums

Use of long, word, byte, res in inline assembly Solved. RET needed!

R BaggettR Baggett Posts: 252
edited 2026-02-17 16:02 in Propeller 2

I never see this:

PUB DoNothingExample(V1,V2,V3):V4,V5|V6

org
                rdlong var1,#@clkfreq
                shl     var1,#1

var1            res 1                
end

And indeed, some code where I tried it is acting up.. Is this not allowed?
Is there a way to get beyond the variable limit for inline code (6, I think?)

Comments

  • evanhevanh Posts: 17,064

    Without an explicit RET added after the SHL, you're attempting to execute whatever is placed in var1.

  • I just did this with an inline FFT. Both res and long are fine. You will need to "ret" before the cog tries to run whatever is in those variables as instructions.

    There are also named registers pr0 through pr7 that may be used by inline assembly.

  • I knew that... Hate when that happens

    THANKS!

  • @SaucySoliton said:
    There are also named registers pr0 through pr7 that may be used by inline assembly.

    THAT, I missed somehow..
    Thanks!

  • JonnyMacJonnyMac Posts: 9,657
    edited 2026-02-17 16:37

    While I was answering an email and editing the demo, everyone answered -- but here it is. I have have used res inside inline PASM a few times.

  • JonnyMacJonnyMac Posts: 9,657
    edited 2026-02-17 16:48

    @"R Baggett" said:

    @SaucySoliton said:
    There are also named registers pr0 through pr7 that may be used by inline assembly.

    THAT, I missed somehow..
    Thanks!

    I have a no-cog version of a WS2812 pixel driver that uses the PRx registers. In this case setregs is used to move global variables into the PRx registers to be used by the inline PASM.

    pub show(swap)
    
    '' Refresh pixels
    '' -- swap.[0] is 1 for red/green swap (WS2812b)
    '' -- cog prX regs:
    ''    0:pin, 1:p_buf/color, 2:count, 3:reset, 4:zero, 5:one, 6:period, 7:timer
    
      setregs(@pixout, PRX_REGS, 7)                                 ' copy hub vars to cog regs pr0..pr6
    
      org
                            drvl      pr0                           ' make output/low
                            waitx     pr3                           ' allow reset
                            mov       ptrb, pr1                     ' point to start of buffer
    
    .pixloop                rdlong    pr1, ptrb++                   ' get pixel data
                            testb     swap, #0              wc      ' swap red & green?
            if_c            movbyts   pr1, #%%2310                  '  yes
                            getct     pr7                           ' initialize bit timer
    
                            rep       #7, #24                       ' loop through all bits
                             shl      pr1, #1               wc      ' get MSB
                             drvh     pr0                           ' pin on
            if_nc            waitx    pr4                           ' hold for bit timing
            if_c             waitx    pr5
                             drvl     pr0                           ' pin off
                             addct1   pr7, pr6                      ' update bit timer
                             waitct1                                ' let bit timing finish
    
                            djnz      pr2, #.pixloop
      end
    
  • @JonnyMac said:
    While I was answering an email and editing the demo, everyone answered -- but here it is. I have have used res inside inline PASM a few times.

    From what I just read, ret may be preferable to ret as an instruction because it skips context restore.. right?

    @JonnyMac said:

    @"R Baggett" said:

    @SaucySoliton said:
    There are also named registers pr0 through pr7 that may be used by inline assembly.

    THAT, I missed somehow..
    Thanks!

    I have a no-cog version of a WS2812 pixel driver that uses the PRx registers. In this case setregs is used to move global variables into the PRx registers to be used by the inline PASM.

      setregs(@pixout, PRX_REGS, 7)                                 ' copy hub vars to cog regs pr0..pr6
    

    Gotta keep that one in the toolbox..
    Thanks!

Sign In or Register to comment.