Propeller Manual

Table Of Contents
CNT – Assembly Language Reference
Page 282 · Propeller Manual v1.1
CNT
Register: System Counter register.
DAT
Label Condition Instruction DestOperand, CNT Effects
Label is an optional statement label. See Common Syntax Elements, page 250.
Condition is an optional execution condition. See Common Syntax Elements, page 250.
Instruction is the desired assembly instruction. CNT is a read-only register and thus
should only be used in the instruction’s source operand.
DestOperand is a constant expression indicating the register that is operated on, and
optionally written to, using the value of
CNT in the instruction’s source operand. T
Explanation
The
CNT register contains the current value in the global 32-bit System Counter. The System
Counter serves as the central time reference for all cogs; it increments its 32-bit value once
every System Clock cycle.
CNT is a read-only pseudo-register; when used as an instruction’s source operand, it reads the
current value of the System Counter. Do not use
CNT as the destination operand; that only
results in reading and modifying the shadow register whose address
CNT occupies.
CNT is often used to determine an initial target value for a WAITCNT-based delay. The
following code performs an operation in a loop every ¼ second. See Registers, page 338, and
the Spin language
CNT section, page 73, for more information.
DAT
org 0 'Reset assembly pointer
AsmCode rdlong Delay, #0 'Get clock frequency
shr Delay, #2 'Divide by 4
mov Time, cnt 'Get current time
add Time, Delay 'Adjust by 1/4 second
Loop waitcnt Time, Delay 'Wait for 1/4 second
'<more code here> 'Perform operation
jmp #Loop 'loop back
Delay res 1
Time res 1