Shop OBEX P1 Docs P2 Docs Learn Events
CALLA #\A Syntax Qestion — Parallax Forums

CALLA #\A Syntax Qestion

CALLA #\A Call to A by writing {C, Z, 10'b0, PC[19:0]} to hub long at PTRA++. If R = 1 then
PC += A, else PC = A. "\" forces R = 0.(404)
** What does PTRA++ mean? The following CALLA #\A example seems to work. Any Comments would be apreciated. **

CON {Processor Timing}
  _clkfreq  = 200_000_000  'processor clock speed
VAR
    Byte cogStarted_COGEXEC_NEW 'cog ID started is returned or -1 if not started

OBJ
PUB main()
     cogStarted_COGEXEC_NEW := COGINIT(COGEXEC_NEW,@CallProgram,PTRA_Stack)
     repeat  'keep cog 0 running
DAT          ORGH
PTRA_Stack   long    10  'need 2 more characters than the stack length required
DAT          ORG   0     'COGINIT(COGEXEC_NEW,@CallProgram,PTRA_Stack)
CallProgram
             CALLA #Subroutine   'Compiler takes Subroutine-Call Program and generates offset
             debug("Returned from Subroutine")
             debug(udec(POPANum01),udec(POPANum02),udec(POPANum03))
             debug(udec(POPANum04),udec(POPANum05),udec(POPANum06),udec(POPANum07))
             debug(udec("Program Completed"))
Loop1        NOP
             JMP  #LooP1
Subroutine   NOP
             debug("Now In Subroutine")
             WAITX clkTicks
             debug("PUSH Num01 to Num07")
             PUSHA Num01
             PUSHA Num02
             PUSHA Num03
             PUSHA Num04
             PUSHA Num05
             PUSHA Num06
             PUSHA Num07
             WAITX clkTicks
             debug("POP POPNum07 to POPNum01")
             POPA   POPANum07
             POPA   POPANum06
             POPA   POPANum05
             POPA   POPANum04
             POPA   POPANum03
             POPA   POPANum02
             POPA   POPANum01
             RETA
Loop2        NOP
             JMP #Loop2
clkTicks     long     $000A0_0000
Num01        long     1
Num02        long     2
Num03        long     3
Num04        long     4
Num05        long     5
Num06        long     6
Num07        long     7
POPANum01     long     0
POPANum02     long     0
POPANum03     long     0
POPANum04     long     0
POPANum05     long     0
POPANum06     long     0
POPANum07     long     0

Comments

  • evanhevanh Posts: 16,027
    edited 2021-10-04 00:40

    PTRA register gets used as a "Stack Pointer", often called the SP register in other CPUs. CALLA places its return address on a stack in hubRAM. As opposed to CALL, which uses the hardware stack. PTRA contains the address of where in hubRAM to store this return address, ie: The stack.

    Trivia: PTRA and PTRB are real registers too - most of cogRAM is made from SRAM cells. Therefore, there is also shadow-RAM behind PTRA and PTRB.

  • PTRA++ means the contents of PTRA which is incremented after use.

    So if PTRA contains 1234 when the CALLA is executed, then {C, Z, 10'b0, PC[19:0]} is written to hubram at 1234 and then PTRA is incremented.

  • TonyB_TonyB_ Posts: 2,193
    edited 2021-10-04 10:32

    As a long is being written, PTRA++ in this case means add 4 to PTRA after the write.

    Generally-speaking:
    PTRx++ adds 4/2/1 after long/word/byte operation
    PTRx-- subtracts 4/2/1 after long/word/byte op
    ++PTRx adds 4/2/1 before long/word/byte op
    --PTRx subtracts 4/2/1 before long/word/byte op

Sign In or Register to comment.