This is an old revision of the document!
Table of Contents
DM41 Save/Restore Statistics
Using Extended Memory to save Statistics Registers
Background
Statistics use 6 regular registers to keep track of data for calculating Mean and Standard Deviations.
Keeping a long-term record of a set of variables means not being able to use the Statistics functions for anything else unless steps are taken to save and restore the registers.
It is possible to save the 6 registers in a data file in Extended Memory and then use the statistics for other things, and restore the saved Statistics back to Main Memory when required.
By Default the Statistics registers start at R11 but this can be changed with the command ∑REG
This is the default list of Statistics Registers and contents
| R11 | ∑x | Summation of x-values |
| R12 | ∑x2 | Summation of squares of x-values. |
| R13 | ∑y | Summation of y-values. |
| R14 | ∑y2 | Summation of squares of y-values. |
| R15 | ∑xy | Summation of products of x- and y-values. |
| R16 | n | Number of data points accumulated. |
Advantage Pac : CFIT application seems to reset ∑REG to 12
Extended Memory Data File
The statistics registers use 6 Main Memory registers, usually R11 → R16
We need to create a Data File in Extended Memory to hold these.
- Put the name in
ALPHAe.g.REGS - Put
6inxregister - excecute
CRFLDto create the Data FileREGSin Extended Memory
Once it's created it can be used to hold the contents of the 6 Statistics Registers
Save Registers to Extended Memory
- We need to make sure our Data File is the current file and that the pointer is at the beginning of the file
- Put
REGSinALPHA - Put
0inXso that we put the pointer at the first register record in the data file. - Execute
SEEKPTA
- Now we need to copy the 6 Registers R11 → R16 to the Data File
REGS- ensure
REGSis still inALPHA - put a number in
Xto indicate which range of Registers to save, this isbbb.eeewherebis the beginning register andeis the end- put
11.016inX
- execute
SAVERX
Restore Registers from Extended Memory to Main Memory
- We need to make sure our Data File is the current file and that the pointer is at the beginning of the file
- Put
REGSinALPHA - Put
0inX - Execute
SEEKPTA
- We can copy the 6 registers held in the Data File
REGSback to R11 → R16- ensure
REGSis still inALPHA - put a number in
Xto indicate where the recovered registers will be put in Main Memory- put
11.016inX
- execute
GETRX
A program to make it easier
It is possible to change the base register of the 6 Statistics Registers, away from the default of R11.
We need to take this into account.
This uses the query ∑REG? to find the base register, then create bbb.eee using simple arithmetic.
When used in SAVER (saveRegs) we ensure we copy the current Statistics Registers data.
When used in GETR (getRegs) we ensure we restore our data to the Registers currently set to be the active Statistics Registers (they may have changed since first saving them)
LBL ¬SAVER ¬REGS 0 SEEKPTA ∑REG? 1.001 * .005 + SAVERX ¬REGS SAVED AVIEW PSE CLD RTN LBL ¬GETR ¬REGS 0 SEEKPTA ∑REG? 1.001 * .005 + GETRX ¬REGS OK AVIEW PSE CLD RTN
Multiple Saved Files
It's possible to have more than one Extended Memory file with Stats registers.
This could keep track of different sets of statistics and allow restore, update, save for many sets of statistical data.
I've set up two data files : REGS and CHESS in extended memory and made two version of the simple program above, the only change is to alter the lines which put the name of the file in ALPHA
Then I thought of adding a 7th Register holding the DATE of the latest SAVE
Delete the original CHESS Data File & make a new one with 7 registers
ALPHA = CHESS
execute PURFL
X = 7 and ALPHA still = CHESS
execute CRFLD
The date is automatically stored in the register just after the Stats - in general in R18 when ΣREG is 12 - and automatically adapts the register used depending on ΣREG?
Here is SAVEC and GETC for saveChess and getChess
LBL ¬SAVEC ¬CHESS 0 SEEKPTA ∑REG? STO 01 6 + STO 00 DATE STO IND 00 RCL 01 1.001 * .006 + SAVERX ¬CHESS SAVED AVIEW PSE CLD RTN END
LBL ¬GETC ¬CHESS 0 SEEKPTA ∑REG? STO 01 6 + STO 00 RCL 01 1.001 * .006 + GETRX CLA RCL IND 00 ¬LAST ADATE AVIEW PSE CLD RTN END
Further Ideas
I might make a better version which prompts for a Data File name rather than having one separate program for each scenario