Propeller Manual

Table Of Contents
3: Assembly Language Reference – RES
Propeller Manual v1.1 · Page 341
:Loop waitcnt Time, Delay 'Wait for time window
nop 'Do something useful
jmp #:Loop 'Loop endlessly
Time RES 1 'Time window workspace
Delay long 6_000_000 'Time window size
This example would be launched into a cog as follows:
Symbol Address Instruction/Data
AsmCode 0 mov
Time, cnt
1 add Time, Delay
:Loop 2 waitcnt Time, Delay
3 nop
4 jmp #:Loop
Time 5 6_000_000
Delay 6 ?
Notice how
Time and Delay are reversed with respect to the previous example but their data is
not? Here’s what happened:
First, the assembler placed everything in the object’s memory image exactly as it did
before up to and including the
JMP instruction.
The assembler reached the
Time symbol, which is declared with a RES directive, so it
equated
Time to address 5 (the current assembly pointer value) and then incremented the
assembly pointer by 1. No data was placed in the application memory image due to this
step.
The assembler reached the
Delay symbol, which is declared as a LONG of data, so it
equated
Delay to address 6 (the current assembly pointer value), incremented the
assembly pointer by 1, then placed the data, 6_000_000, into the next available location
in the memory image right after the
JMP instruction which happens to be where Time is
logically pointing.
The effect when launched into a cog is that the
Time symbol occupies the same Cog RAM
space that
Delay’s initial value does, and Delay exists in the next register that contains
unknown data. The code will fail to run as intended.
For this reason, it is best to place
RES statements after the last instruction and after the last
defined data that your assembly code relies upon, as shown in the first example.