CALLA #\A Syntax Qestion
Bob Drury
Posts: 236
in Propeller 2
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
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.
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