PAD program listing

 

 

Program:

Comments:

 

 

 

 

 

 

«

 

 

 

→STR

Makes sure the object is in string form. (Strings

 

 

 

are unaffected by this command.)

 

 

WHILE

Repeats if the string contains fewer than 22

 

 

DUP SIZE 22 <

characters.

 

 

REPEAT

Loop-clause adds a leading space.

 

 

" " SWAP +

 

 

 

END

End loop.

 

 

»

 

 

 

`OPAD K

Stores the program in PAD.

 

 

 

 

 

 

Checksum: # 6577d

 

Bytes:

57.5

 

PAD is demonstrated in the program BDISP.

PRESERVE (Save and Restore Previous Status)

PRESERVE stores the current calculator (flag) status, executes a program from the stack, and restores the previous status.

Level 1

Level 1

 

 

 

«program»

result of program

'program'

result of program

 

 

 

Techniques used in PRESERVE

Preserving calculator flag status. PRESERVE uses RCLF (recall flags) to record the current status of the calculator in a binary integer, and STOF (store flags) to restore the status from that binary integer.

Local-variable structure. PRESERVE creates a local variable structure to briefly remove the binary integer from the stack. Its defining procedure simply evaluates the program argument, then puts the binary integer back on the stack and executes STOF.

Error trapping. PRESERVE uses IFERR to trap faulty program execution on the stack and to restore flags. DOERR shows the error if one occurs.

2-6 RPL Programming Examples