PAR

Register: Cog Boot Parameter register.

((PUBPRI))
   PAR


Returns: Address value passed during launch of assembly code with COGINIT or COGNEW.

Explanation

The PAR register contains the address value passed into the Parameter field of a COGINIT or COGNEW command; see COGINIT and COGNEW. The PAR register's contents are used by Propeller Assembly code to locate and operate on memory shared between Spin code and assembly code.

Since the PAR register is intended to contain an address upon cog launch, the value stored into it via COGINIT and COGNEW is limited to 14 bits: a 16-bit word with the lower two bits cleared to zero.

Using PAR

PAR is affected by Spin code and is used by assembly code as a memory pointer mechanism to point to shared main memory between the two. Either the COGINIT or COGNEW command, when launching Propeller Assembly into a cog, affects the PAR register. For example:

VAR
  long Shared                         'Shared variable (Spin & Assy) 

PUB Main | Temp
  cognew(@Process, @Shared)           'Launch assy, pass Shared addr
  repeat
    <do something with Shared vars> 

DAT
                 org 0
  Process        mov Mem, PAR         'Retrieve shared memory addr :loop <do something>
  :loop          <do something>
                 wrlong ValReg, Mem   'Move ValReg value to Shared
                 jmp #:loop 
  Mem    res 1
  ValReg res 1

In the example above, the Main method launches the Process assembly routine into a new cog with COGNEW. The second parameter of COGNEW is used by Main to pass the address of a variable, Shared. The assembly routine, Process, retrieves that address value from its PAR register and stores it locally in Mem. Then it performs some task, updating its local ValReg register (created at the end of the DAT block) and finally updates the Shared variable via wrlong ValReg, Mem.

In Propeller Assembly, the PAR register is read-only so it should only be accessed as a source (s-field) value (i.e., mov dest, source).

Unless otherwise noted, content on this site is licensed under the
Creative Commons Attribution-ShareAlike 4.0 International License.