HP (Hewlett-Packard) HP-42S Calculator User Manual


 
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 +
03 RTN
04 LBL A
05 5
06 ENTER
07 7
08 XEQ S
09 1
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