Reference Guide

RPL Programming Examples 2-17
MNX program listing
Program: Comments:
«
{{ "MAX"
« 10 SF CONT » }
{ "MIN"
« 10 CF CONT » }}
Defines the option menu.
%MAX%
sets
flag 10 and continues execution.
%MIN%
clears flag 10 and continues
execution.
TMENU
"Sort for MAX or MIN?"
PROMPT
Displays the temporary menu and a
prompt message.
1 GETI
Gets the first element of the array.
DO
Begins the DO loop.
ROT ROT GETI
Puts the index and the array in levels
1 and 2, then gets the new array
element.
4 ROLL DUP2
Moves the current minimum or
maximum array element from level 4
below 1, then copies both.
IF
> 10 FS? XOR
Tests the combined state of the
relative value of the two elements and
the status of flag 10.
THEN
SWAP
END
If the new element is either less than
the current maximum or greater than
the current minimum, swaps the new
element into level 1.
DROP
Drops the other element off the
stack.
UNTIL
-64 FS?
Begins the DO test-clause.
Tests if flag
64 is set — if the index
reached the end of the array.
END
Ends the DO loop.
SWAP DROP 0 MENU
Swaps the index to level 1 and drops
it. Restores the last menu.
»
`O
MNX K
Stores the program in MNX.
Checksum: # 20991d
Bytes: 194.5
Example: Find the maximum element of the following matrix:
12 56
45 1
9 14