The Museum of HP Calculators

HP Forum Archive 21

[ Return to Index | Top of Index ]

wp34s INC s function
Message #1 Posted by Jeff O. on 2 Oct 2012, 1:06 p.m.

I apologize in advance if this question has been asked and answered previously. I did read the fine manual, and attempted to search the archives, but could not find the answer. The question is, is it intentional behavior that register L is not updated when applying the INC function to the value in the stack X register. In other words, this happens:

Keystroke	X display
1		1
ENTER		1
2		2
+		3
INC X		4
RCL L		2 (equals the “2” used in the plus operation above, which was not the last value in X)

Instead of this:

Keystroke	X display
1		1
ENTER		1
2		2
+		3
INC X		4
RCL L		3 (equals the “3”, which was the last value in X prior to the INC X function)

Thanks.

...

      
Re: wp34s INC s function
Message #2 Posted by Walter B on 2 Oct 2012, 4:11 p.m.,
in response to message #1 by Jeff O.

If I'd document it the way it works (i.e. not loading L), it would be a feature ;-) After all, LASTx is primarily for error recovery IMHO, so not loading L in INC doesn't hurt, it's just not documented. Or is there any *need* for loading L here?

            
Re: wp34s INC s function
Message #3 Posted by Jeff O. on 2 Oct 2012, 4:29 p.m.,
in response to message #2 by Walter B

Well, I "needed" it when I determined that it did not operate that way :-)

LASTx’s primary use may be error recovery, but seeing as how functions like RCL+L, RCL-L, X<>L, etc. are allowed, it is also useful for general data manipulation. So should INC X, which is after all a function that could be called “X+1”, load L just like any* other function operating on X?

* - I did not do an exhaustive search to determine if there are any other situations where something is done to the value in X that does not load L.

...

            
Re: wp34s INC s function
Message #4 Posted by Gerson W. Barbosa on 2 Oct 2012, 5:32 p.m.,
in response to message #2 by Walter B

One of these days I intended to use INC X in a program, but I quit because it didn't update the L register. I shifted to the HP-42S instead and used NOT, even though this is equivalent to 1 + +/- (for integers in the valid range). I think both DEC and INC should update the L register, but only when they act on X, if this is not difficult to implement.

                  
Re: wp34s INC s function
Message #5 Posted by Paul Dale on 2 Oct 2012, 5:42 p.m.,
in response to message #4 by Gerson W. Barbosa

What does the 41C/42S do with "STO+ ST X" and the LastX register?

This is the same case.

- Pauli

                        
Re: wp34s INC s function
Message #6 Posted by Gerson W. Barbosa on 2 Oct 2012, 6:44 p.m.,
in response to message #5 by Paul Dale

I see your point. Fortunately on the HP-42S we have "RCL+ST X", which behaves differently regarding the LastX register :-)

Gerson.

                              
Re: wp34s INC s function
Message #7 Posted by Paul Dale on 2 Oct 2012, 6:51 p.m.,
in response to message #6 by Gerson W. Barbosa

On the 34S RCL register arithmetic sets L appropriately too :-) This makes sense since X is always changes. For STO arithmetic (and INC and DEC), X isn't always changed so L is left alone. There is some logic here :-)

- Pauli

                                    
Re: wp34s INC s function
Message #8 Posted by Jeff O. on 2 Oct 2012, 10:10 p.m.,
in response to message #7 by Paul Dale

I see your points. Probably a trivial issue, one that will never impact me again. I just wanted to make sure it was intentional.

In this case, I was to trying create x(x+1) without disturbing the stack by the following steps:

INC X
RCLxL

But the following does the job:

X^2
RCL+L

...

Edited: 3 Oct 2012, 7:40 a.m.

                        
Re: wp34s INC s function
Message #9 Posted by Marcus von Cube, Germany on 3 Oct 2012, 3:20 a.m.,
in response to message #5 by Paul Dale

To add to Pauli's comment, what about INC->nn where nn contains 100? Updating LastX would be dependent on the data, not only on the command alone. Looks like a Pandoara's box to me which should be better left unopened.

      
Re: wp34s INC s function
Message #10 Posted by Paul Dale on 2 Oct 2012, 5:14 p.m.,
in response to message #1 by Jeff O.

This behaviour is intentional. Likewise for DEC. The only register it might make sense for is X and if we did it then, we'd have an exception which is bad. Better for these to just not touch L unless it is their argument.

- Pauli

            
Re: wp34s INC s function
Message #11 Posted by Reth on 3 Oct 2012, 1:25 a.m.,
in response to message #10 by Paul Dale

Quote:
This behaviour is intentional. Likewise for DEC...
Than it should be stated in section "last x behaviour" if one exists. Similar to stack lift/disable characteristic of different functions. Intuitively I would think DEC would load L with X.
                  
Re: wp34s INC s function
Message #12 Posted by Walter B on 3 Oct 2012, 8:52 a.m.,
in response to message #11 by Reth

Quote:

Than it should be stated in section "last x behaviour" if one exists. Similar to stack lift/disable characteristic of different functions. Intuitively I would think DEC would load L with X.


There isn't such a section yet, but it may change ;-) OTOH, stack lift should be documented completely.
                        
Re: wp34s INC s function
Message #13 Posted by Paul Dale on 3 Oct 2012, 5:36 p.m.,
in response to message #12 by Walter B

We should also get sections for carry and overflow in integer mode like the 16c manual has.

- Pauli

                              
Re: wp34s INC s function
Message #14 Posted by Walter B on 4 Oct 2012, 4:41 a.m.,
in response to message #13 by Paul Dale

For carry please see p. 55 :-)

                                    
Re: wp34s INC s function
Message #15 Posted by Paul Dale on 4 Oct 2012, 4:47 a.m.,
in response to message #14 by Walter B

That's seven of the carry altering functions. See the 16c manual page 98 for some more. That is still not a comprehensive list.

- Pauli

                                          
Re: wp34s INC s function
Message #16 Posted by Walter B on 4 Oct 2012, 4:57 a.m.,
in response to message #15 by Paul Dale

Literally copying old manuals is little fun :-( So I may point to that manual instead ...

                                                
Re: wp34s INC s function
Message #17 Posted by Paul Dale on 4 Oct 2012, 5:26 a.m.,
in response to message #16 by Walter B

I find 55 commands that change carry and/or overflow. The 16c manual only lists 16 commands.

      Command           Carry    Overflow            
      +                   X         X                   
      -                   X         X                   
      times                         X                   
      /                   X       zero              
      LCM                           X                   
      X^2                           X                   
      X^3                           X                   
      +/-                           X                   
      ABS                           X                   
      DBL[times]                  zero              
      DBL/                X       zero              
      DBLmod                      zero              
      DBLrmdr                     zero              
      SL                  X                             
      SR                  X                             
      ASR                 X                             
      RR                  X                             
      RL                  X                             
      RRC                 X                             
      RLC                 X                             
      SQRT                X                             
      y^x                 X         X                   
      LG2                 X                             
      2^x                 X         X                   
      LOG                 X                             
      10^x                          X                   
      (-1)^x                        X                   
      FIB                           X                   
      RECV1                         X                   
      LN                  X         X                   
      E^x                 X         X                   
      CUBERT              X         X                   
      x!                  X         X                   
      GAMMA               X         X                   
      LOGXY               X         X                   
      COMB                X         X                   
      PERM                X         X                   
      XROOT               X         X                   
      INC                 X         X                   
      DEC                 X         X                   
      ISZ                 X         X                   
      DSZ                 X         X                   
      ISG                 X         X                   
      DSE                 X         X                   
      ISE                 X         X                   
      DSL                 X         X                   
      STO+                X         X                   
      STO-                X         X                   
      STO[times]                    X                   
      STO/                X       zero              
      RCL+                X         X                   
      RCL-                X         X                   
      RCL[times]                    X                   
      RCL/                X       zero              

- Pauli

Edited: 4 Oct 2012, 5:41 a.m.

            
Re: wp34s INC s function
Message #18 Posted by 'Angel Martin on 3 Oct 2012, 2:14 a.m.,
in response to message #10 by Paul Dale

I certainly wouldn't argue about such a minor point but my SandMath's INCX and DECX functions do store X in L.

If you consider Inc() and Dec() to be -trivial- functions then x is their argument.

However DSE/ISG ST X do not save it, so that's supporting your approach.

Either way is good, a consistent implementation is better... but "consistency is in the eye of the beholder"

Cheers, 'AM

                  
Re: wp34s INC s function
Message #19 Posted by Paul Dale on 3 Oct 2012, 2:20 a.m.,
in response to message #18 by 'Angel Martin

Remember the 34S's INC and DEC take a register argument and increment or decrement that. In fact, the share code with DSE/ISG/DSZ/iSZ/DSL/ISE.

If we'd implemented an explicit INCX/DECX, it would have saved X into L.

Additionally, my experience with INC/DEC supports the don't touch L viewpoint. I've written plenty of programs where leaving L intact was a benefit. Of course, most programs really don't care either way.

- Pauli


[ Return to Index | Top of Index ]

Go back to the main exhibit hall