Shop OBEX P1 Docs P2 Docs Learn Events
Passimg multiple parameters to PASM — Parallax Forums

Passimg multiple parameters to PASM

John BoardJohn Board Posts: 371
edited 2013-07-15 01:16 in Propeller 1
G'day,

Just wondering how I pass multiple parameters (in this case, variable pointers), to PASM code. Or to achieve this would I pass one variable pointer, and then somehow be able to change the other variable using the same pointer..? Add 4(?) to the pointer?

Thanks,

John

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2013-07-14 23:24
    Pass the address of a long array via par. The elements of the array will be your multiple parameters.

    -Phil
  • John BoardJohn Board Posts: 371
    edited 2013-07-14 23:35
    Ohh, so obvious, I'm so silly, thanks for this, but how do I access the different elements of the array in PASM?

    Top "Object":
    CON
    
    
      _clkmode = xtal1+pll16x
      _xinfreq = 5_000_000
    
    
    OBJ
    
    
      SigmaDelta      : "SigmaDelta"
      Serial          : "Serial"
    
    
    VAR
    
    
      long readings[2]
    
    
    PUB Main
    
    
      Serial.start(31, 30, 0, 9600)
      SigmaDelta.SigmaDelta(@readings)
    
    
      repeat
        Serial.tx(16)
        Serial.dec(readings[1])
        Serial.tx(13)
        Serial.dec(readings[2])
        waitcnt(clkfreq/2+cnt)
    

    SigmaDelta Library:
    {{
    *****************************************
    * generic ADC driver v1.0               *
    * Author: Beau Schwabe                  *
    * Copyright (c) 2007 Parallax           *
    * See end of file for terms of use.     *
    *****************************************
    }}
    CON
        SDF1 = 6                     'sigma-delta feedback
        SDI1 = 7                     'sigma-delta input
        SDF2 = 4
        SDI2 = 5
    
    
    PUB SigmaDelta (sample)
        cognew(@asm_entry, sample)   'launch assembly program in a COG
    
    
    DAT
                  org
    
    
    asm_entry     mov       dira,#1<<SDF1                    'make SDF pin an output
                  movs      ctra,#SDI1                       'POS W/FEEDBACK mode for CTRA
                  movd      ctra,#SDF1
                  movi      ctra,#%01001_000
                  mov       frqa,#1
    
    
                  
                 { mov       dira,#1<<SDF2
                  movs      ctrb,#SDI2
                  movd      ctrb,#SDF2
                  movi      ctrb,#%01001_000
                  mov       frqb,#1      }
                                
    
    
                  mov       asm_c1,cnt                       'prepare for WAITCNT loop
                  add       asm_c1,asm_cycles
                  
    :loop         waitcnt   asm_c1,asm_cycles                'wait for next CNT value
                                                            '(timing is determinant after WAITCNT)
    
    
                  mov       asm_new1,phsa                    'capture PHSA
                  mov       asm_new2,phsb
    
    
                  mov       asm_sample1,asm_new1             'compute sample from 'new' - 'old'
                  sub       asm_sample1,asm_old1
                  mov       asm_old1,asm_new1
    
    
                  'mov       asm_sample2, asm_new2
                  'sub       asm_sample2, asm_old2
                  'mov       asm_old2, asm_new2
                  
                  wrlong    asm_sample1,par                 'write sample back to Spin variable "sample" 
                  wrlong    asm_sample2,par+1              '(WRLONG introduces timing indeterminancy here..)
                                                            '(..since it must sync to the HUB)                                                                      
                                                            
                  jmp       #:loop                          'wait for next sample
    
    
                  
    
    
    asm_cycles    long      $FFFF                           '(use $FFFF for 16-bit, $FFF for 12-bit, or $FF for 8-bit)
    
    
    asm_c1         res       1                               'uninitialized variables follow emitted data
    asm_cnt1       res       1
    asm_new1       res       1
    asm_old1       res       1
    asm_sample1    res       1
    asm_temp1      res       1
    asm_c2         res       1                               'uninitialized variables follow emitted data
    asm_cnt2       res       1
    asm_new2       res       1
    asm_old2       res       1
    asm_sample2    res       1
    asm_temp2      res       1
    
    
    DAT
    {{
    &#9484;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9488;
    &#9474;                                                   TERMS OF USE: MIT License                                                  &#9474;
    &#9500;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9508;
    &#9474;Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation    &#9474;
    &#9474;files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,    &#9474;
    &#9474;modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software&#9474;
    &#9474;is furnished to do so, subject to the following conditions:                                                                   &#9474;
    &#9474;                                                                                                                              &#9474;
    &#9474;The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.&#9474;
    &#9474;                                                                                                                              &#9474;
    &#9474;THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE          &#9474;
    &#9474;WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR         &#9474;
    &#9474;COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,   &#9474;
    &#9474;ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                         &#9474;
    &#9492;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9472;&#9496;
    }}
    

    I'm wanting to access the par flag on the lines "wrlong asm_sample1, par", and the line below that. So for example, what would I put in to write asm_sample1 to the first element, and then asm_sample2 to the second?

    Cheers,

    John
  • AribaAriba Posts: 2,690
    edited 2013-07-14 23:35
    Either you define the variables as a block and then pass only the address of the first variable. The following can be calculated at begin of the pasm code:
    VAR
      long  var1,var2,var3
    
    PUB
      cognew(@asm,@var1)
      ...
    
    DAT
    asm  mov vp1,par
         mov vp2,par
         add vp2,#4
         mov vp3,par
         add vp3,#8
         ...
    
    vp1  res 1
    vp2  res 1
    vp3  res 1
    

    If this is not possible then you can use a mailbox (an array with the variable pointers, as Phil suggested):
    VAR
      long  mailbox[3]
      long  var1,var5,var2,var7,var3
    
    PUB
      mailbox[0] := @var1
      mailbox[1] := @var2
      mailbox[2] := @var3
      cognew(@asm,@mailbox)
      ...
    
    DAT
    asm  mov tmp,par
         rdlong vp1,tmp
         add tmp,#4
         rdlong vp2,tmp
         add tmp,#4
         rdlong vp3,tmp
         ...
    
    vp1  res 1
    vp2  res 1
    vp3  res 1
    

    Andy
  • John BoardJohn Board Posts: 371
    edited 2013-07-15 01:16
    G'day,

    Worked, thank you very much!

    -John
Sign In or Register to comment.