MNX2 program listing

 

 

Program:

Comments:

 

 

 

 

 

 

«

 

 

 

{{ "MAX"

Defines the temporary option menu. %MAX%

 

 

« 10 SF CONT » }

sets flag 10 and continues execution. %MIN%

 

 

{ "MIN"

 

 

clears flag 10 and continues execution.

 

 

« 10 CF CONT » }}

 

 

 

 

 

TMENU

Displays the temporary menu and a

 

 

"Sort for MAX or MIN?"

prompting message.

 

 

PROMPT

 

 

 

DUP OBJ→

Copies the array. Returns the individual array

 

 

 

elements to levels 2 through nm+1, and

 

 

 

returns the list containing n and m to level 1.

 

 

1

Sets the initial counter value.

 

 

SWAP OBJ→

Converts the list to individual elements on

 

 

 

the stack.

 

 

DROP * 1 -

Drops the list size, then calculates the final

 

 

 

counter value (nm - 1).

 

 

FOR n

Starts the FOR…NEXT loop.

 

 

DUP2

Saves the array elements to be tested (initially

 

 

 

the last two elements). Uses the last array

 

 

 

element as the current minimum or

 

 

 

maximum.

 

 

IF

Tests the combined state of the relative value

 

 

> 10 FS? XOR

of the two elements and the status of flag 10.

 

 

THEN

If the new element is either less than the

 

 

SWAP

current maximum or greater than the current

 

 

END

minimum, swaps the new element into level

 

 

 

1.

 

 

DROP

Drops the other element off the stack.

 

 

NEXT

Ends the FOR…NEXT loop.

 

 

0 MENU

Restores the last menu.

 

 

»

 

 

 

 

 

 

 

`OMNX2 K

Stores the program in MNX2.

 

 

 

 

 

 

Checksum: # 6992d

 

Bytes:

188.5

 

Example: Use MNX2 to find the minimum element of the matrix from the previous example:

1256

451

9 14

Enter the matrix (or retrieve it from the previous example).

RPL Programming Examples 2-19