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.
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: