Skip to content

Symbol Address operator

rosco-pc edited this page Feb 11, 2015 · 1 revision

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:

  • The COG code can become smaller, as it can be computed according to the specificsituation and need not contain all unused variations
  • This might be the only way to stay within the COG's 2k limit
  • The COG code can become simpler when you (dynamically) arrange all its parameters in a cunning way ("pushing"), rather than let it find everything out itself ("pulling") 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 :-)
Clone this wiki locally