Post Reply 
Programming help, please. HP-67 Moving Averages
07-07-2017, 05:21 PM
Post: #6
RE: Programming help, please. HP-67 Moving Averages
(07-06-2017 10:39 PM)Matt Agajanian Wrote:  Over the last few days, I've been diving into the 67's Standard Pac Moving Averages program.

There seems to be a treasure chest of programming tricks, looping, and indirect addressing genius. I feel overwhelmed trying to mentally grasp each technique.

Well, it's not that complicated. There is just a special way of handling the loop counter.

(07-06-2017 10:39 PM)Matt Agajanian Wrote:  Perhaps some folks here can give me a detailed sketch of how the program flows and its indirect addressing tricks.

LBL a initializes the program in that it clears all registers, checks whether the input n (the number of values to average) is between 1 and 22 (if not the input flashes, cf. LBL 4). As in many other HP programs, flag 0 is used to indicate print mode, in this case some results are printed. The most important part is that register I is initialized with the number n,nn (i.e. n + n/100). Since for indirect addressing only the integer part is relevant, register I is set to n, the highest register number where the first value will be stored.

LBL A is the main routine that accepts a new value and – after n values have been entered – calculates the average. First the number of entered values k is increased by one (RCL E 1 +), then the oldest value in register (i) is removed from the sum in R0 (RCL i STO-0) and the entered value both replaces it as well as it's added back to the sum (STO i x<>y STO+0). The new number of entered values is compared with n, and if n has been reached, the average is calculated (GSB 0).

Then the pointer in register I is decremented. If you want to average 5 values, the first entry has been stored in R5, and now the pointer is adjusted to R4. If the pointer falls below one (checked by the DSZ in line 48) the content of register I is 0,nn. In this case this is multiplied by 101 which resets this number to n,nn: 0,05*101 = 5,05. So this simply wraps around the pointer: 5 - 4 - 3 - 2 - 1 - 0 - 5 - 4... A simple RCL D STO I would have done the same. ;-)

The output routine at LBL C essentially uses the same trick. The FRC command resets n,nn to 0,nn.

LBL D recalculates the average by dividing the cumulated sum by min(n, k).

That's it.

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


Messages In This Thread
RE: Programming help, please. HP-67 Moving Averages - Dieter - 07-07-2017 05:21 PM



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