Techniques used in BDISP
IFERR…THEN…END (error trap). To accommodate
Enabling LASTARG. In case an error occurs, the LASTARG recovery feature must be enabled to return the argument (the binary number) to the stack. BDISP clears flag
FOR…NEXT loop (definite loop with counter). BDISP executes a loop from 1 to 4, each time displaying n (the number) in a different base on a different line. The loop counter (named j in this program) is a local variable created by the FOR…NEXT program structure (rather than by a → command), and automatically incremented by NEXT.
Unnamed programs as arguments. A program defined only by its « and » delimiters (not stored in a variable) is not automatically evaluated, but is placed on the stack and can be used as an argument for a subroutine. BDISP demonstrates two uses for unnamed program arguments:
BDISP contains a main program argument and a call to PRESERVE. This program argument goes on the stack and is executed by PRESERVE.
BDISP also contains four program arguments that “customize” the action of the loop. Each of these contains a command to change the binary base, and each iteration of the loop evaluates one of these arguments.
When BDISP creates a local variable for n, the defining procedure is an unnamed program. However, since this program is a defining procedure for a local variable structure, it is automatically executed.
Required Programs
PAD
PAD (Pad with Leading Spaces) expands a string to 22 characters so that DISP shows it
PRESERVE
PRESERVE stores the current status, executes the main nested program, and restores the status.