The Museum of HP Calculators

HP Forum Archive 18

[ Return to Index | Top of Index ]

Program only works when stepping, not when running?
Message #1 Posted by Mark Edmonds on 5 Nov 2008, 9:27 a.m.

I've got a little 32sII program that doesn't work when I run it but if I step through it, it works!

I am confused by this. I know where the program fails when I run it (an Enter command) so when the Enter command in the program is processed, x is not duplicated when running but is duplicated when stepping.

This means there is a programmatic difference with the Enter command compared to interactive which I've never seen before. If I put two Enter commands in the program, it does what I expect one Enter command to do.

Maybe my brain is fried today but is this difference in Enter functionality a known issue?

Thanks :)

Mark

      
Re: Program only works when stepping, not when running?
Message #2 Posted by Eric Smith on 5 Nov 2008, 2:13 p.m.,
in response to message #1 by Mark Edmonds

On some HPs, SST changes the "stack lift enabled" flag, so SSTing through a program may give different results than running it normally. I'm not sure which models have that "feature", but perhaps the 32SII is one of them.

            
Re: Program only works when stepping, not when running?
Message #3 Posted by Mark Edmonds on 5 Nov 2008, 2:48 p.m.,
in response to message #2 by Eric Smith

Well, that must be it Eric. I've never seen that documented anywhere so it is rather useful to know!

Here is the listing. It is a simple thing.

LBL R
INPUT R
INPUT X
INPUT Y
x SWAP y
/ (divide)
*
SQRT
ENTER // Duplicate the result of the SQRT
RCL X
RCL / Y
x
STOP

That is the version that only works when stepping through it. To get it to work when running, you need to add another ENTER after the ENTER so it reads

SQRT
ENTER
ENTER
RCL X


The use of the 2nd Enter totally confused me.

When running the program typical values might be 12, 3, 2 and use x SWAP y to get the result pair.

Mark

                  
Re: Program only works when stepping, not when running?
Message #4 Posted by Didier Lachieze on 6 Nov 2008, 4:24 a.m.,
in response to message #3 by Mark Edmonds

As you want to have two copies of the same number in the stack you need the two ENTER as the stack lift is disabled after each ENTER. As stated in the 32SII manual:

ENTER replicates the content of the X-register into the Y-register. The next number you key in (or recall) writes over the copy of the first number left in the X-register. The effect is simply to separate two entered numbers.

This means that after a single ENTER you have the SQRT result in the Y-register and in the X-register, but the RCL X writes over the X-register so you end up with only one copy of the SQRT result in the Y-register and you have the X value in the X-register.

As Eric said above the SST instruction may change the stack lift enable flag on the HP 32sII and allow the RCL X to not overwrite the X-register but instead to move the values in the Y_register and X-register to the Z-register and Y_register.

I've tried your program on my 35s and there is no difference between running and single stepping modes: two ENTER are needed (and thanks to the two lines display there is no need to swap x & y to see the result pair...)

            
Re: Program only works when stepping, not when running?
Message #5 Posted by Mike T. on 6 Nov 2008, 6:36 a.m.,
in response to message #2 by Eric Smith

The only similar example I can remember encountering is that on some earlier models (HP33C, HP11C, HP34C) R/S seems to enable stack lift but SST does not. (Though I can't remember what the manuals say about stack lift and R/S without checking).

The result is that this can have the opposite effect - running a program will 'work' but single stepping it doesn't.

Mike T.

                  
Re: Program only works when stepping, not when running?
Message #6 Posted by Mark Edmonds on 6 Nov 2008, 6:58 a.m.,
in response to message #5 by Mike T.

Thanks for all your help chaps. With the benefit of a clearer brain today, I can now explain exactly what was going wrong. The route cause of the problem was operator error! I could see where things were going wrong but I was totally on the wrong track.

I typed in the program, ran it and found it gave wrong results so I stepped through it and found it gave right results. This totally confused me and made me look at things the wrong way - I thought it was a bug in the 32sII or my program, not that it was actually my fault!

The reason is that when I was stepping through, after the Enter command, I was checking the stack contents by using "x swap y" which of course, enabled stack lift and therefore cancelled the disabled stack lift after the Enter command. Hence, the stepped run gave the right answer. Had I tried stepping through the program without checking the stack, I would have found that it also gave the wrong answer!

So, like most code mysteries, the cause was simple operator error and me looking for the solution in the wrong place (which had I applied my 5 minute rule, I would have stopped doing).

A somewhat embarrassing saga but a good one to learn and a nice way to remind myself that even if you consider yourself competent at programming, simple mistakes are still simple to make! :)

Mark


[ Return to Index | Top of Index ]

Go back to the main exhibit hall