RES
Directive: Reserve next long(s) for symbol.
< Symbol > RES < Count >
- Symbol is an optional name for the reserved long in Cog RAM.
- Count is the optional number of longs to reserve for Symbol. If not specified, RES reserves one long.
Explanation
The RES (reserve) directive effectively reserves one or more longs of Cog RAM by incrementing the compile-time assembly pointer by Count. Normally this is used to reserve memory for an assembly symbol that does not need initialization to any specific value. For example:
DAT ORG 0 AsmCode mov Time, cnt 'Get system counter add Time, Delay 'Add delay :Loop waitcnt Time, Delay 'Wait for time window nop 'Do something useful jmp #:Loop 'Loop endlessly Delay long 6_000_000 'Time window size Time RES 1 'Time window workspace
The last line of the AsmCode example, above, reserves one long of Cog RAM for the symbol Time without defining an initial value. AsmCode uses Time as a long variable to wait for the start of a time window of 6 million clock cycles. When AsmCode is launched into a cog, it is loaded into Cog RAM as shown below.
Symbol | Address | Instruction/Data |
AsmCode | 0 | mov Time, cnt |
1 | add Time, Delay | |
:Loop | 2 | waitcnt Time, Delay |
3 | nop | |
4 | jmp #:Loop | |
Delay | 5 | 6_000_000 |
Time | 6 | ? |
RES simply increments the compile-time assembly pointer that affects further symbol references (Cog RAM); it does not consume space in the object (Main RAM). This distinction is important in how it impacts the object code, initialized symbols, and affects run-time operation.
- Since it increments the compile-time assembly pointer only, the computed address of all symbols following a RES statement are affected accordingly.
- No space is actually consumed in the object/application (Main RAM). This is an advantage if defining buffers that should only exist in Cog RAM but not Main RAM.
Unless otherwise noted, content on this site is licensed under the
Creative Commons Attribution-ShareAlike 4.0 International License.