Previous page Next page Navigation bar

Programs

Utility Programs

Variable Save/Restore Routines

Summary Description

Programs:

VRPRE, VRSAVFJ, VRSAVKO, VRSAVPT, VRSAVUY, VRRESFJ, VRRESKO, VRRESPT, VRRESUY

Version:

1.0, 10 February 2002

Description:

These programs save and restore blocks of five variables.

Compatibility:

Is compatible CFX-9850G

Compatible with CFX-9850G

Is compatible FX-7400G

Compatible with FX-7400G

Other programs
required:

None.

Detailed Description

These programs save and restore the values of blocks of variables. This saving and restoring creates the effect of local variables by making the use of variables by a routine transparent to programs that call the routine. Variable values are saved into List 6, starting from element 1 and going towards element 255. The variable Z is used as an index giving the last used element in List 6.

The alphabetic calculator variables are regarded as five sets of five variables each: A-E, F-J, K-O, P-T, and U-Y. The physics programs pass arguments and results in the first set, A-E, so no provision is made to save and restore these variables. Routines are provided to save and to restore each of the four other sets of five variables. The variable save routines have names VRSAVab, where a is the name of the first variable saved and b is the name of the last variable saved. The variable restore routines have names VRRESab, where a and b are the names of the first and last variable restored.

In addition, the VRPRE routine is provided to initialize the storage used to save and restore variables. This routine must be called once, and must be called before any routine using the variable save and restore routines are called. It is recommended that this routine be called from the main program of any program using routines using the variable save and restore routines. The VRPRE routine initializes List 6 to be 255 elements long, and initializes the Z variable to be zero.

The maximum call depth supported by the calculator is 10 routines. The maximum number of variables that can be saved by any one routine is 20. Therefore, the maximum number of elements used in List 6 can be expected to be 200. The extra elements in List 6 are allocated to provide for variable block copying, saving of intermediate results, and so forth.

A client program can save one or more blocks of variables. However, when more than one block of variables is saved, the blocks of variables must be restored in the reverse order of that in which they were saved. For example, a routine may save variables F through T with three calls, to VRSAVFJ, VRSAVKO, and VRSAVPT, in that order. To restore the variable contents, the variable restore routines must be called in the order VRRESPT, VRRESKO, and VRRESFJ.

Usage

Load the program VRPRE, and the routines VRSAVab and VRRESab for all blocks of variables a through b required. Before calling any routine using the variable save and restore routines, call the VRPRE routine with the statement:

Prog "VRPRE"

A defined variable block (F-J, K-O, P-T, and U-Y) may be saved with the statement:

Prog "VRSAVab"

where a is the first variable in the block and b is the last variable in the block. A defined variable block may be restored with the statement:

Prog "VRRESab"

where a and b are as before.

Program Source

The programs are available as a text file with .CAT contents, or may be entered as shown below. A semicolon (“;”) marks the beginning of a comment, which is not to be entered into the calculator. Remember that these programs are copyrighted; see the copyright issues page for limitations on redistribution.

Program VRPRE (39 bytes):

; Program VRPRE
;
; Description:
;   Initializes the variable save/restore routines. This routine must
;   be called before any of the variable save/restore routines are
;   called.
;
; Formal parameters:
;   None.
;
; Calling sequence:
;   Prog "VRPRE"
;
; Implicit inputs:
;   None.
;
; Implicit outputs:
;   List 6: the variable save stack.
;   Z: the stack pointer for the variable save stack.
;
; Side effects:
;   None.
;
; Symbols used:
;   -> is assignment arrow
 
Seq(0,Z,1,255,1)->List 6
                   ; Initialize List 6
0->Z               ; Initialize Z

Program VRSAVFJ (75 bytes):

; Program VRSAVFJ
;
; Description:
;   Saves the variables F through J on the List 6 stack. The routine
;   VRPRE must have been called to initialize the stack and stack
;   pointer.
;
; Formal parameters:
;   None.
;
; Calling sequence:
;   Prog "VRSAVFJ"
;
; Implicit inputs:
;   F through J: the variables to be saved.
;   Z: the stack pointer for the variable save stack.
;
; Implicit outputs:
;   List 6: the variable save stack.
;   Z: the stack pointer for the variable save stack.
;
; Side effects:
;   None.
;
; Symbols used:
;   -> is assignment arrow
 
Z+5->Z             ; Increment stack pointer
F->List 6[Z-4]     ; Save F
G->List 6[Z-3]     ; Save G
H->List 6[Z-2]     ; Save H
I->List 6[Z-1]     ; Save I
J->List 6[Z]       ; Save J

Program VRSAVKO (75 bytes):

; Program VRSAVFJ
;
; Description:
;   Saves the variables K through O on the List 6 stack. The routine
;   VRPRE must have been called to initialize the stack and stack
;   pointer.
;
; Formal parameters:
;   None.
;
; Calling sequence:
;   Prog "VRSAVKO"
;
; Implicit inputs:
;   K through O: the variables to be saved.
;   Z: the stack pointer for the variable save stack.
;
; Implicit outputs:
;   List 6: the variable save stack.
;   Z: the stack pointer for the variable save stack.
;
; Side effects:
;   None.
;
; Symbols used:
;   -> is assignment arrow
 
Z+5->Z             ; Increment stack pointer
K->List 6[Z-4]     ; Save K
L->List 6[Z-3]     ; Save L
M->List 6[Z-2]     ; Save M
N->List 6[Z-1]     ; Save N
O->List 6[Z]       ; Save O

Program VRSAVPT (75 bytes):

; Program VRSAVPT
;
; Description:
;   Saves the variables P through T on the List 6 stack. The routine
;   VRPRE must have been called to initialize the stack and stack
;   pointer.
;
; Formal parameters:
;   None.
;
; Calling sequence:
;   Prog "VRSAVPT"
;
; Implicit inputs:
;   P through T: the variables to be saved.
;   Z: the stack pointer for the variable save stack.
;
; Implicit outputs:
;   List 6: the variable save stack.
;   Z: the stack pointer for the variable save stack.
;
; Side effects:
;   None.
;
; Symbols used:
;   -> is assignment arrow
 
Z+5->Z             ; Increment stack pointer
P->List 6[Z-4]     ; Save P
Q->List 6[Z-3]     ; Save Q
R->List 6[Z-2]     ; Save R
S->List 6[Z-1]     ; Save S
T->List 6[Z]       ; Save T

Program VRSAVUY (75 bytes):

; Program VRSAVUY
;
; Description:
;   Saves the variables U through Y on the List 6 stack. The routine
;   VRPRE must have been called to initialize the stack and stack
;   pointer.
;
; Formal parameters:
;   None.
;
; Calling sequence:
;   Prog "VRSAVUY"
;
; Implicit inputs:
;   U through Y: the variables to be saved.
;   Z: the stack pointer for the variable save stack.
;
; Implicit outputs:
;   List 6: the variable save stack.
;   Z: the stack pointer for the variable save stack.
;
; Side effects:
;   None.
;
; Symbols used:
;   -> is assignment arrow
 
Z+5->Z             ; Increment stack pointer
U->List 6[Z-4]     ; Save U
V->List 6[Z-3]     ; Save V
W->List 6[Z-2]     ; Save W
X->List 6[Z-1]     ; Save X
Y->List 6[Z]       ; Save Y

Program VRRESFJ (75 bytes):

; Program VRRESFJ
;
; Description:
;   Restores the variables F through J from the List 6 stack. The
;   routine VRSAVFJ just have been called to save the F through J
;   variables on the stack before this routine is called.
;
; Formal parameters:
;   None.
;
; Calling sequence:
;   Prog "VRRESFJ"
;
; Implicit inputs:
;   List 6: the variable save stack.
;   Z: the stack pointer for the variable save stack.
;
; Implicit outputs:
;   F through J: the variables restored.
;   Z: the stack pointer for the variable save stack.
;
; Side effects:
;   None.
;
; Symbols used:
;   -> is assignment arrow
 
List 6[Z]->J       ; Restore J
List 6[Z-1]->I     ; Restore I
List 6[Z-2]->H     ; Restore H
List 6[Z-3]->G     ; Restore G
List 6[Z-4]->F     ; Restore F
Z-5->Z             ; Decrement stack pointer

Program VRRESKO (75 bytes):

; Program VRRESKO
;
; Description:
;   Restores the variables K through O from the List 6 stack. The
;   routine VRSAVKO just have been called to save the K through O
;   variables on the stack before this routine is called.
;
; Formal parameters:
;   None.
;
; Calling sequence:
;   Prog "VRRESKO"
;
; Implicit inputs:
;   List 6: the variable save stack.
;   Z: the stack pointer for the variable save stack.
;
; Implicit outputs:
;   K through O: the variables to be saved.
;   Z: the stack pointer for the variable save stack.
;
; Side effects:
;   None.
;
; Symbols used:
;   -> is assignment arrow
 
List 6[Z]->O       ; Restore O
List 6[Z-1]->N     ; Restore N
List 6[Z-2]->M     ; Restore M
List 6[Z-3]->L     ; Restore L
List 6[Z-4]->K     ; Restore K
Z-5->Z             ; Decrement stack pointer

Program VRRESPT (75 bytes):

; Program VRRESPT
;
; Description:
;   Restores the variables P through T from the List 6 stack. The
;   routine VRSAVPT just have been called to save the P through T
;   variables on the stack before this routine is called.
;
; Formal parameters:
;   None.
;
; Calling sequence:
;   Prog "VRRESPT"
;
; Implicit inputs:
;   List 6: the variable save stack.
;   Z: the stack pointer for the variable save stack.
;
; Implicit outputs:
;   P through T: the variables to be saved.
;   Z: the stack pointer for the variable save stack.
;
; Side effects:
;   None.
;
; Symbols used:
;   -> is assignment arrow
 
List 6[Z]->T       ; Restore T
List 6[Z-1]->S     ; Restore S
List 6[Z-2]->R     ; Restore R
List 6[Z-3]->Q     ; Restore Q
List 6[Z-4]->P     ; Restore P
Z-5->Z             ; Decrement stack pointer

Program VRRESUY (75 bytes):

; Program VRRESUY
;
; Description:
;   Restores the variables U through Y from the List 6 stack. The
;   routine VRSAVUY just have been called to save the U through Y
;   variables on the stack before this routine is called.
;
; Formal parameters:
;   None.
;
; Calling sequence:
;   Prog "VRRESUY"
;
; Implicit inputs:
;   List 6: the variable save stack.
;   Z: the stack pointer for the variable save stack.
;
; Implicit outputs:
;   U through Y: the variables to be saved.
;   Z: the stack pointer for the variable save stack.
;
; Side effects:
;   None.
;
; Symbols used:
;   -> is assignment arrow
 
List 6[Z]->Y       ; Restore Y
List 6[Z-1]->X     ; Restore X
List 6[Z-2]->W     ; Restore W
List 6[Z-3]->V     ; Restore V
List 6[Z-4]->U     ; Restore U
Z-5->Z             ; Decrement stack pointer

The text file with .CAT contents contains a unit test in addition to these routines.

[ Previous page | Top of page | Next page ]

Previous page Top of page Next page Navigation bar

Copyright © 2002 Brian Hetrick
Page last updated 28 April 2002.

Brian’s Casio Calculator Corner

Home

Programs

Index

Linkage Conventions

Mathematics

Finance

Physics

Utility

Index

Save/Restore

Line Drawing

Boolean Operations

Bitwise Operations

Tutorial

Puzzles

Site Information

Your Privacy

Site Map

E-mail

Site Technical Data