Symbol Address operator
Title:Symbol Address operator
Author:deSilva
Published:Sun, 23 Dec 2007 11:24:04 GMT

Obtaining a Cog Address from Spin


To obtain the cog address of a label in a DAT section from spin the method used is -

cogAddress := @ cogLabel >> 2 - @ cogBaseLabel >> 2

This will return the address of the cog label ( $000-$1F0 ).

For example, the cog address of 'CogLabel' is $003 in the following example
DAT
              org   $000
 
CogBaseLabel  nop          ' $000
              nop          ' $001
              nop          ' $002
CogLabel      nop          ' $003
This is nice to know, but will there be any use?
Well, an advanced programming style consists of generating your COG machine program "on the fly", or at least thoroughly "parametrize" it using SPIN.
This has some advantages:
Note that the formula above depends on ORG having been set to $000, otherwise this offset has to be added. Note also that using an ORG <> 0 is VERY advanced :-)