Post Reply 
EXC/ x<>Rn for stack efficiency
06-15-2017, 11:05 AM (This post was last modified: 06-17-2017 07:23 PM by Dieter.)
Post: #24
RE: EXC/ x<>Rn for stack efficiency
(06-14-2017 11:31 PM)Matt Agajanian Wrote:  General Aircraft Weight and Balance

A strange program – I'm not sure at all what it does.

But there are lots of EXC instructions between line 10 and 27. There are even consecutive EXC commands that neutralize each other. #-) If you take a closer look at this you will realize that the sequence with all these obscured EXC commands simply does this: Store an entry in R4, then check if R0 is zero. If yes, add the previous entry to R2, otherwise add R3*entry to R2. At the end R0 is left unchanged.

Of course this can be coded much more effectively and simpler:

Code:
...
STO 4
RCL 0
X=0?
GTO nn  -----+
R↓           |
RCL 3        |
x            |
ENTER        |
R↓      <----+
STO+2

That's shorter and less obscure.
BTW, the STO 4 is not required, neither in the SR56 program nor in the translation above: R4 is not used elsewhere in the program.

Edit: the instructions for this program say that the previous entry may be recalled by RCL 4, e.g. for correcting the last entry, so this is the reason why the input is stored in R4 although this register is not recalled in the program itself.

While I am still not sure what the program is supposed to do (what are these 3, 4 and 5 prompts for?) I think it can be done in 30 steps on an HP25 or 33. Or three more if the program initially resets R1 and R2 to zero, which I think it should do. Here is an experimental, completely untested first attempt at this:

Code:
01  STO 0
02  CLX
03  STO 1
04  STO 2
05  3
06  R/S
07  STO 3
08  4
09  R/S
10  RCL 0
11  X=0?
12  GTO 17
13  R↓
14  RCL 3
15  x
16  ENTER
17  R↓
18  STO+2
19  RCL 3
20  STO+1
21  5
22  R/S
23  X≠0?
24  GTO 07
25  RCL 1
26  R/S
27  RCL 2
28  R/S
29  RCL 2
30  RCL 1
31  /
32  R/S
33  GTO 21

And finally in the original SR56 program all these obscure EXC-sequences could be avoided like this:

Code:
...
10  STO
11  4
12  CP
13  RCL
14  0
15  x=t?
16  2
17  2
18  RCL
19  3
20  PRD
21  4
22  RCL
23  4
24  SUM
25  2

That's even four steps shorter.

Dieter
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: EXC/ x<>Rn for stack efficiency - Dieter - 06-15-2017 11:05 AM



User(s) browsing this thread: 2 Guest(s)