HP 42S manual Enter, X?0 and X?Y sub-menus

Page 21

When in programing mode XEQ function is programed and when the program finds the XEQ function it changes to the given program which must finish with RTN function.

So LBL “label” and RTN makes a kind of procedure and after the procedure is run it goes back to the previous position.

Example:

01 LBL S

02+

03RTN

04LBL A

055

06ENTER

077

08XEQ S

091

10-

11.END.

This program called “A” creates a procedure “S” which does only a simple addition. In the line 07 the XEQ “S” makes the program to go to the procedure “S” and after that it goes back to the line next line 07 which is of course the line 08. The calculation is 5+7-1 which gives 11.

You can use programmed GTO and XEQ even to call a label in another program space but this is not exactly a good use.

6.3 The X?0 and X?Y sub-menus.

Up to now we saw nothing about how we could do a IF instruction, like what we have in computer's programming languages like BASIC, Pascal or C.

In fact there is no IF, THEN, ELSE, ELSEIF, etc in the HP-42S programming language but there are

12 test functions which are:

X=0?, X≠0?, X<0?, X>0?, X≤0?, X≥0?

and

X=Y?, X≠Y?, X<Y?, X>Y?, X≤Y?, X≥Y?

The first group of functions involving the number 0 is accessed by the X?0 sub-menu which is available in the second line of the ▀ PGN.FCN menu. The second group is accessed by the X?Y sub-menu also in the second line of the ▀ PGN.FCN menu.

How do these functions work? Let's consider the first function “X=0?”. If the number in the first line of the stack (line x) is zero than the program works normally and it goes to the next line after “X=0?” instruction. But if the condition is not true than the program jumps the next line and goes to the second line after the instruction. Usually the line after the instruction has a GTO “label” command and this makes the difference in the program flux.

All the other functions involving the 0 work in the same way. If the condition is true the program

Image 21
Contents An alternative HP-42S/Free42 Manual Version 2005 Index Introduction RPN Basic OperationsSetting the display contrast Training RPN using HP-42STurn ON/OFF FIX, SCI, ENG, ALL, RDX., RDX MenusPage Stack Modes MenuGetting used to some keys of the keyboard Page Abcde Fghi Jklm Nopq Rstuv Wxyz Memory More on the Clear menu Catalog menuCustom menu Assign FCN ABSAssign ABS to Probability Where N!=N.N-1.N-2...2.1Page Complex Numbers Complex numbers in rectangular coordinatesComplex numbers in polar coordinates Basic programming Programming19STOP More than one program in the memory X?0 and X?Y sub-menus EnterReal program examples LBL PrimeSqrt Select Solve Program Using the SolverPage Ba f  xdx Numeric IntegrationStatistics Enter 6 Σ+Sub-menu Cfit Second line ALLΣ, LINΣ, Σreg and ΣRG? Functions Matrices = B Enter Matrix NEWMatrix 1 Enter 3 NEW Enter NEW Enter ComplexEnter 3 NEW Edit 1 Enter →→5 +/- Enter Exit STO B RCL a RCL B Matrix CrossOther Bases Flags License