Propeller Manual

Table Of Contents
3: Assembly Language Reference – JMPRET
stored, the DestAddress routine is executed, and finally control returns to the instruction
following the
JMPRET. See CALL on page 268 for more information.
When used a little differently, the
JMPRET instruction can aid in single-process multi-tasking.
This is done by defining a set of registers to hold various destination and return addresses and
specifying those registers for the RetInstAddr and DestAddress fields. For example:
Initialize mov Task2, #SecondTask 'Initialize 1st Dest.
FirstTask <start of first task>
...
jmpret Task1, Task2 'Give 2nd task cycles
<more first task code>
...
jmpret Task1, Task2 'Give 2nd task cycles
jmp #FirstTask 'Loop first task
SecondTask <start of second task>
...
jmpret Task2, Task1 'Give 1st task cycles
<more second task code>
...
jmpret Task2, Task1 'Give 1st task cycles
jmp #SecondTask 'Loop second task
Task1 res 1 'Declare task address
Task2 res 1 'storage space
In this example there are two routines, FirstTask and SecondTask, which serve as separate
tasks in the cog process. The function each task performs is relatively irrelevant; they may do
similar or dissimilar operations.
Task1 and Task2 are longs, declared at the end of code, used
to hold the destination and return addresses that facilitate the switching of execution between
the two tasks.
The first instruction, mov Task2,#SecondTask, stores the address of SecondTask into the Task2
register. This primes the task registers for the first task-switch event.
Once
FirstTask starts, it performs some operations denoted by “…” and reaches the first
JMPRET instruction, jmpret Task1,Task2. First, JMPRET saves the return address (PC + 1, the
address of
<more first task code>) into the s-field of the Task1 register, then it jumps to the
Propeller Manual v1.1 · Page 301