The Museum of HP Calculators

HP Forum Archive 17

[ Return to Index | Top of Index ]

Initializing Values in a Program (HP35s)
Message #1 Posted by Chuck on 3 Oct 2007, 12:41 p.m.

Suppose you need to initialize X=2 and Y=3 in a program. One method is:

001  2
002  STO X
003  3
004  STO Y

A second method is to use EQN before each line

001  2 -> X
002  3 -> Y

where -> is the STO command.

The second method obviously reduces the number of lines of code, but is one method any more efficient (timewise) over the other? I haven't been able to discern a difference in my small programs, so it's just really a matter of curiousity.

CHUCK

      
Re: Initializing Values in a Program (HP35s)
Message #2 Posted by Egan Ford on 3 Oct 2007, 1:02 p.m.,
in response to message #1 by Chuck

Create a loop and time it:

E.g.:

A001 100
A002 STO I
A003 your code here
...
An   DSE I
An+1 GTO A003
An+2 RTN
This will run your code 100 times. Use a stopwatch to time it.

Edited: 3 Oct 2007, 1:03 p.m.

            
Re: Initializing Values in a Program (HP35s)
Message #3 Posted by Arne Halvorsen (Norway) on 3 Oct 2007, 1:20 p.m.,
in response to message #2 by Egan Ford

Y001 LBL Y
Y002 0.999
Y003 STO X
Y004 2
Y005 STO Y
Y006 ISG X
Y007 GTO Y004
Y008 RTN

Used 1m 8s

Y001 LBL Y
Y002 0.999
Y003 STO X
Y004 eq 2>Y
Y005 ISG X
Y006 GTO Y004
Y007 RTN

Used 1m 57s

Edited: 3 Oct 2007, 1:22 p.m.

            
Re: Initializing Values in a Program (HP35s)
Message #4 Posted by Chuck on 3 Oct 2007, 2:01 p.m.,
in response to message #2 by Egan Ford

Okay, I looped it 100 times.

11 seconds with

2
sto x
3
sto y

and 20 seconds with

2 -> x
3 -> y

Looks like there is definitely a trade-off with speed -vs- size.

                  
Re: Initializing Values in a Program (HP35s)
Message #5 Posted by Meenzer on 3 Oct 2007, 2:40 p.m.,
in response to message #4 by Chuck

The difference in length is only

LBL A
2
STO
LN=67

LBL A
2>A
LN=66

Edited: 3 Oct 2007, 2:43 p.m.

                        
Re: Initializing Values in a Program (HP35s)
Message #6 Posted by Arne Halvorsen (Norway) on 3 Oct 2007, 3:04 p.m.,
in response to message #5 by Meenzer

Equation are parsed run time every time used, so clearly there will by an overhead.

                        
Re: Initializing Values in a Program (HP35s)
Message #7 Posted by Paul Dale on 3 Oct 2007, 5:08 p.m.,
in response to message #5 by Meenzer

I've not checked if this is the case here or not but don't trust the reported program lengths, they are wrong.

To measure sizes more accurately, try looking at the change in the bytes free in the memory menu.

- Pauli


[ Return to Index | Top of Index ]

Go back to the main exhibit hall