Knowledge Base

The instruction

     SPxPoll1   2,!CPU

will return the current subroutine stack pointer in U0. This is twice the number of levels of subroutine stacking. This can be useful during debugging to check how many level of nesting you have left.

Example: This program will “nest down” one level of subroutine each time push button input 8 is pressed on an MMi99, and display the nesting level on the LCD. The program will crash and restart when the subroutine stack overflows, and the displayed number will revert to 0. Expect an error report when you re-connect with SPLat/PC!

Again OBLCD_SetCur      0,0
SPxPoll1 2,!CPU
PushU 0
RorM ;Binary divide by 2
OBLCD_UDecDispXVW

WaitOnK 8
GoSub Again

Note that we can use a RorM (rotate) as a divide by 2 because in this case we know the number we are dealing with is even. If it could be an odd number then an extra masking would be necessary, viz:

      RorM                       ;Binary divide by 2
LoadX '7F
AndM