Jumping between slots.

BeanieBots

Moderator
Could someone please indicate if my assumptions are valid or if there are hidden dangers in what I'm proposing.

The idea is to create a program which can jump between slots using a common variable to determine where to go.

Assumption 1.
All variables gauranteed to be zero at power up.

Assumption 2.
Gosub stack is reset when a slot is run.

Example:

#Slot 0
Branch b0,(L0,L1,L2,L3.........)

L0: 'This will ALWAYS be run after a power cycle?

L1: 'This will be run if/when slot N (or anything else) sets b0 to 1 and executes a run slot 0.

L2:
Gosub Subroutine

L3:
etc. etc.

End

Subroutine:
'some other code here
Run Slot N
Return

This return is actually superfluous as the stack is reset when slot N executes a run slot 0 to come back. (having set b0 to some other value). Correct?

A similar construct would also be created in slot N using another variable for program control.

My concern (besides any bad programming practice) is if I can be confident that the stack really is reset rather simply cannot be relied on to 'return' to the correct location.

The above example could simply use a goto but I envisage maybe being down several gosub nestings when a descision is made to run another slot.
Most probably from within an interrupt where the handler is in another slot which then sets b0 accordingly and 'returns' to slot 0 with b0 set accordingly so that slot 0 then continues down a different path.
 
Last edited:

hippy

Ex-Staff (retired)
All variables gauranteed to be zero at power up.
Yes - Standard PICAXE start-up initialisation.

Gosub stack is reset when a slot is run.
Yes - "This command stops the current program and starts the second program running immediately. Variables and pin conditions are not reset, so can be shared between the programs. However all other system functions, such as the gosub/return stack, are reset when the second program starts".

Run Slot N
Return

This return is actually superfluous as the stack is reset when slot N executes a run slot 0 to come back. (having set b0 to some other value). Correct?
Yes.

The above example could simply use a goto but I envisage maybe being down several gosub nestings when a descision is made to run another slot.
Most probably from within an interrupt where the handler is in another slot which then sets b0 accordingly and 'returns' to slot 0 with b0 set accordingly so that slot 0 then continues down a different path.
Yes, that should work.
 

BeanieBots

Moderator
Thanks for the confirmation.
I've now tried it and it works fine.

Being able to pop out and return to a specified location approximates a single level "gosub slot" which is a very useful feature for large programs with large auxiliary functions such as menu selections.

The 28X2 really is a great device:D
 
Top