If you continue a subroutine that was stopped with R/S, the next RTN will only work if the subroutine was called by label (Either directly or by a positive number in the I register), not if it was called by line number (negative number in I).
To be precise:
- GTO works always
- GSB A works
- GSB A where the subroutine contains an R/S works
- GSB I where I=20 ("A") works
- GSB I where I=20 ("A") and the subroutine contains an R/S works
- GSB I where I=-1 (line of A) works
- GSB I where I=-1 (line of A) and the subroutine contains an R/S does not work, because the return stack seems to disappear, so the next RTN returns to 000 and stops
You can test this with these programs (Launch "B"):
Doesn't work when resuming the program with R/S:
LBL A
20
R/S
RTN
LBL B
1
CHS
STO I
GSB I
21 ; unreachable code
RTN
This works, the only difference is that it uses GSB A instead of GSB I
LBL A
20
R/S
RTN
LBL B
1
CHS
STO I
GSB A
21 ; fine, will show up
RTN
Also works, only difference is no R/S in the subroutine:
LBL A
20
RTN
LBL B
1
CHS
STO I
GSB I
21 ; fine
RTN
Also fine, I contains "A" as 20
LBL A
20
R/S
RTN
LBL B
20
STO I
GSB I
21 ; fine
RTN
The manual does not use GSB with line numbers, but I think that the correct behaviour would be to only wipe the subroutine call stack when the user interrupts the program control flow, i.e. by using the buttons A-E or GSB 0 etc.
I don't actually have an HP calculator, can anybody confirm this behaviour on a real HP15C?
[DM15L M1B V28] Using R/S in a subroutine reached by line number wipes the call stack
-
- Posts: 41
- Joined: Tue Apr 10, 2018 11:34 pm
Re: [DM15L M1B V28] Using R/S in a subroutine reached by line number wipes the call stack
This seems to be a bug of the original 15C firmware that was fixed by changing the manual to remove the reference to GSB I with I<0. See this discussion .
DM42: 00425 - DM41X: β00066 - WP43: 00042
Re: [DM15L M1B V28] Using R/S in a subroutine reached by line number wipes the call stack
Nice find Didier.dlachieze wrote: ↑Mon May 27, 2019 11:32 pmThis seems to be a bug of the original 15C firmware that was fixed by changing the manual to remove the reference to GSB I with I<0. See this discussion .
I tend to agree with Message #11 Posted by Michael de Estrada in that thread. GSB is intended to go to a labeled routine that has a RTN; arbitrary jumps to line numbers is fine (it's a plain 'ol GOTO) but a Gosub to an arbitrary line number is poor programming so they probably prevented it. As to whether it was a bug in the 15C and then covered-up with a manual edit, or a design change after some early manuals were released, guess we'll never know. In any case though the DM15 should clearly behave the same as genuine HP-15Cs.
--bob p
DM42: β00071 & 00282, DM41X: β00071 & 00656, DM10L: 071/100
DM42: β00071 & 00282, DM41X: β00071 & 00656, DM10L: 071/100
-
- Posts: 41
- Joined: Tue Apr 10, 2018 11:34 pm
Re: [DM15L M1B V28] Using R/S in a subroutine reached by line number wipes the call stack
Not if you only use this to jump to specific line numbers because you ran out of labels.
Personally, I think it should behave like a bug free HP-15C instead. But judging from the linked discussion I guess this would be very difficult to fix.
I guess I'll either have to do label budgeting or write my own gosub stack.
Re: [DM15L M1B V28] Using R/S in a subroutine reached by line number wipes the call stack
Bug or not, this was not really needed in the limited RAM of the 15C, so even if it was a bug, it appears there was insufficient motivation to fix it.michaelzinn wrote: ↑Tue May 28, 2019 8:19 amNot if you only use this to jump to specific line numbers because you ran out of labels.
Personally, I think it should behave like a bug free HP-15C instead. But judging from the linked discussion I guess this would be very difficult to fix.
I guess I'll either have to do label budgeting or write my own gosub stack.
How would you go about writing your own gosub stack? Do you mean use GTO I with flags and such to simulate a GSB/RTN ?
--bob p
DM42: β00071 & 00282, DM41X: β00071 & 00656, DM10L: 071/100
DM42: β00071 & 00282, DM41X: β00071 & 00656, DM10L: 071/100
Re: [DM15L M1B V28] Using R/S in a subroutine reached by line number wipes the call stack
Depending on what you class as a bug, both the HP-15C and the DM15 are bug-free...michaelzinn wrote: ↑Tue May 28, 2019 8:19 amPersonally, I think it should behave like a bug free HP-15C instead.
Personally I don't consider this a bug. The original 15C had a maximum of 448 bytes (not steps, some instructions use 2 bytes) and it was not unreasonable to think that the 25 available labels should suffice. With the DM15_M80 and DM15_M1B you get 896 or 1603 bytes respectively. OK, you still have to spread the 25 available labels in that space but you're still getting more than you were with the original. Don't complain
There are only 10 kinds of people in the world: those who understand binary and those who do not.
-
- Posts: 41
- Joined: Tue Apr 10, 2018 11:34 pm
Re: [DM15L M1B V28] Using R/S in a subroutine reached by line number wipes the call stack
Not sure, one way would be to put the stack pointer in register 0, having it contain the register number that contains the line number to jump to on return.
GOSUB could then look like this:
1. Put the target line number on the stack
2. Put the line number after the GTO on the stack
3. GTO 1
LBL 1
CHS
1
RCL+0
STO 0
STO I
CLx
+
STO (i)
x><y
STO I
GTO I
Returning would be simpler, just do GTO 2
LBL 2
RCL 0
STO I
1
-
STO 0
GTO (i)
This is not tested.
I'll have to ponder the problem for some time since there are several ways to approach this. For example, if I only need labels for GOSUB but not GOTO (always works) or FUNCTION calls (Can use GSB with a line number, since function never contain R/S) the 25 labels might be enough.
Re: [DM15L M1B V28] Using R/S in a subroutine reached by line number wipes the call stack
There is an easier workaround as described in the post #46 of the discussion I linked above: just replace the GSB I by a GSB to a label followed by GTO I.michaelzinn wrote: ↑Tue May 28, 2019 5:28 pmNot sure, one way would be to put the stack pointer in register 0, having it contain the register number that contains the line number to jump to on return.
DM42: 00425 - DM41X: β00066 - WP43: 00042
-
- Posts: 41
- Joined: Tue Apr 10, 2018 11:34 pm
Re: [DM15L M1B V28] Using R/S in a subroutine reached by line number wipes the call stack
But how does that help if one has no available labels, which was the reason for switching from GSB Label to GSB I ?dlachieze wrote: ↑Tue May 28, 2019 5:37 pmThere is an easier workaround as described in the post #46 of the discussion I linked above: just replace the GSB I by a GSB to a label followed by GTO I.michaelzinn wrote: ↑Tue May 28, 2019 5:28 pmNot sure, one way would be to put the stack pointer in register 0, having it contain the register number that contains the line number to jump to on return.
Anyhow, I'd say you'd get better results reorganizing the program to somehow get it done with 25 labels and using flags or register contents as flags if more is absolutely needed.
--bob p
DM42: β00071 & 00282, DM41X: β00071 & 00656, DM10L: 071/100
DM42: β00071 & 00282, DM41X: β00071 & 00656, DM10L: 071/100