program calling with BS2e, BS2sx, BS2p
Hi Peter, it is much more efficient now.
One suggestion. I would have the main0: routine (reset vector)
initialize the stack pointer (as a byte--forget doing it as a nib--go
for broke!).
>main0:
'init
stackpointer var byte
stackpointer=TOS ' top of stack, = 62 for BS2e or BS2sx
That simplifies the following and makes your original stack math
regarding + and - signs correct:
put StackPointer,$08 ' <---simplified stack math
> StackPointer=StackPointer-1
> TargetID=$74 'constant: entryID in highnib, runID in lownib
> run TargetID 'execute entry 14 in program 4, then return to entry01
Same in the ReturnFromProgramCall:
>ReturnFromProgramCall_0:
> StackPointer=StackPointer+1 'adjust stack here
get StackPointer,TargetID 'get TargetID <--- simplified stack math
> run TargetID 'return to parent program
If the set of targetIDs are declared as constants, the intent can be
more transparent:
entryo1 con $08 ' 1st ID in bank 0 for return
myroutine con $74 ' 14th ID in bank 4
In my routines I left them strictly highnib/lownib for transparency
in naming, so that $74 is the seventh routine in bank 4. The extra
bit can still be used ad hoc. Here, you do gain 32 instead of 16
targets, at the expense of slightly less transparency in naming and a
just a slightly more code.
I might put in a little protection against stack overrun, underrun. I.e.
BOS con 50 ' bottom limit for stack
stackpointer = stackpointer -1 min BOS ' for all decrements
stackpointer = stackpointer + 1 max TOS ' for all increments
I don't see how you could use that stack easily to pass parameters
(for recursive algorithms, say). The return ID would always have to
be shuffled to the bottom of the stack. That would push the BS2 to
the limit!
-- regards,
Tracy Allen
electronically monitored ecosystems
mailto:tracy@e...
http://www.emesystems.com
One suggestion. I would have the main0: routine (reset vector)
initialize the stack pointer (as a byte--forget doing it as a nib--go
for broke!).
>main0:
'init
stackpointer var byte
stackpointer=TOS ' top of stack, = 62 for BS2e or BS2sx
That simplifies the following and makes your original stack math
regarding + and - signs correct:
put StackPointer,$08 ' <---simplified stack math
> StackPointer=StackPointer-1
> TargetID=$74 'constant: entryID in highnib, runID in lownib
> run TargetID 'execute entry 14 in program 4, then return to entry01
Same in the ReturnFromProgramCall:
>ReturnFromProgramCall_0:
> StackPointer=StackPointer+1 'adjust stack here
get StackPointer,TargetID 'get TargetID <--- simplified stack math
> run TargetID 'return to parent program
If the set of targetIDs are declared as constants, the intent can be
more transparent:
entryo1 con $08 ' 1st ID in bank 0 for return
myroutine con $74 ' 14th ID in bank 4
In my routines I left them strictly highnib/lownib for transparency
in naming, so that $74 is the seventh routine in bank 4. The extra
bit can still be used ad hoc. Here, you do gain 32 instead of 16
targets, at the expense of slightly less transparency in naming and a
just a slightly more code.
I might put in a little protection against stack overrun, underrun. I.e.
BOS con 50 ' bottom limit for stack
stackpointer = stackpointer -1 min BOS ' for all decrements
stackpointer = stackpointer + 1 max TOS ' for all increments
I don't see how you could use that stack easily to pass parameters
(for recursive algorithms, say). The return ID would always have to
be shuffled to the bottom of the stack. That would push the BS2 to
the limit!
-- regards,
Tracy Allen
electronically monitored ecosystems
mailto:tracy@e...
http://www.emesystems.com