Jeremy Leach
Senior Member
Just wondering, now we've got a scratchpad, if others have considered this, and what people's ideas are?
I'm thinking that could keep the upper half of the 28 byte variables as 'global variables' and the other half put on a stack. So every time you call a subroutine you 'Put' the current 14 variables onto the stack, then have the b0 to b13 variables free to use in your subroutine.
The 28X1 has an 8 level stack, and the memory required is 8 * 14 = 112 bytes which fits into the scratchpad nicely.
All you need is an entry and exit routine in each subroutine - on entry you save the current b0-b13 variables to the stack, on exit you retrieve them. The exit routine can be a 'goto exit routine' rather than a return, where the exit routine includes the return statement. The entry routine, if called within the subroutine, would reduce the possible stack level to 7, so it might be best to save variables before calling subroutines.
This idea will of course introduce some overhead, but might make coding a LOT simpler, where each subroutine has a free range of 14 variables and can have it's own set of symbol declarations. Could also dedicate a set of these 14 variables to be 'parameters' passed to and from the subroutine.
I'm thinking that could keep the upper half of the 28 byte variables as 'global variables' and the other half put on a stack. So every time you call a subroutine you 'Put' the current 14 variables onto the stack, then have the b0 to b13 variables free to use in your subroutine.
The 28X1 has an 8 level stack, and the memory required is 8 * 14 = 112 bytes which fits into the scratchpad nicely.
All you need is an entry and exit routine in each subroutine - on entry you save the current b0-b13 variables to the stack, on exit you retrieve them. The exit routine can be a 'goto exit routine' rather than a return, where the exit routine includes the return statement. The entry routine, if called within the subroutine, would reduce the possible stack level to 7, so it might be best to save variables before calling subroutines.
This idea will of course introduce some overhead, but might make coding a LOT simpler, where each subroutine has a free range of 14 variables and can have it's own set of symbol declarations. Could also dedicate a set of these 14 variables to be 'parameters' passed to and from the subroutine.