eRe emi eC
VSeeseeeeueseeeeegS
Ca sess:(ad HEME
(EB PackaRD
RPN SCIENTIFIC
Va —o om + GRAD
vi £ 3x3 Matrix 1
x: 42,6008
[|S OR ee eas 12
| je & GIGIWOCG)| |
Tome Sa
78 OMG ej e]|
caTALog | "1
GEES
1. Converts to/from complex 9. Shows full precision of number.
numbers. 10. Run/stop program.
2. Menu for typing characters. 11. Catalogs of functions, pro-
3. Enters a number. grams, and variables.
4. Moves up/down through amenu 12. Menu-selection keys.
or program. 13. Backspace.
5. Shift key. 14. Functions for clearing.
6. Calculator OFF. 15. Menu keys (top row).
7. Exits current menu or mode. 16. Two-line display.
8. Top-row functions. 17. Display annunciators.
COCECECECECECOCCEECECOCECECECOCOCECOCECCEE
CCC ¢
tHEWLETT-PACKARD
For Your HP-42S:
An Invisible Link for Visible Results
An added bonus to using the J [P-42S is
seeing your work on paper. The HP
Infrared Printer (82240A) will print
all your steps as you work or only
what you tell it to.
The printer is cordless — infrared
signals make the print connection.
No cords clutter your workspace.
Four AA alkaline batteries give
the HP Infrared Printer go-
anywhere portability. Or, to
extend battery life, plug in the
optional AC adapter.
Accessories
Printer Adapters
US/Canada 82241A
Japan 82241AJ
Europe 82241AB
UK 82241AU
Australia 82241AG
Thermal Printing Paper
Black printing, 82175A
6 rolls per box
Leather Cases
For the HP-42S For the HP Infrared Printer
Black 92169K Black 92169G
Brown. 92169L Brown 92169H
Burgundy 92169M Burgundy 92169)
Application Book for the HP-42S
Programming Examples and Techniques
(00042-90020)
® Solving problems in science, engineering and business with these
built-in applications:
* the equation-solving function
* integration
= matrices
= statistics
™ Using the equation-solving and integration functions in programs
@ Enhancing HP-41 programs for the HP-42S (with examples)
® Building plots and graphics with the HP-42S
§ Printing plots and graphics with the HP Infrared PrinterFor More Information
In the U.S.A., visit your nearest HP dealer for additional information on
calculator accessories or a demonstration of Hewlett-Packard professional
calculators. For the location and number of the dealer nearest you, call
toll-free 800-752-0900.
For items your local dealer does not carry, and for information about
availability and prices of accessories for calculators which are no longer in
production, call toll-free 800-538-8787. Please refer to Call Code P280 when __
ordering. MasterCard, Visa and American Express cards are welcome.
Outside the U.S.A., contact your local HP sales office. It is listed in your
telephone directory.
U.S.A, Other countries:
Hewlett-Packard Co. Hewlett-Packard Intercontinental
Corvallis Division 3495 Deer Creek Road
1000 NE Circle Blvd. Palo Alto, California 94304
Corvallis, OR 97330 USA.
Canada: Hewlett-Packard Corporate Offices
Hewlett-Packard (Canada) Ltd. 3000 Hanover Street
6877 Goreway Drive Palo Alto, California 94304
Mississauga, Ontario USA
L4V IMB
Europe, North Africa, Middle East:
Hewlett-Packard S.A.
7, rue du Bois-du Lan
P.O. Box 364
CH-1217 Meyrin 1
Geneva
Switzerland
Note: Product availability subject to change without notice.
CA eackano
Printed in U.S.A.
8/88HP-42S
Owner’s Manual
HEWLETT
PACKARD
Edition 1 June 1988
Reorder Number 00042-90001Notice
For warranty and regulatory information for this calculator, see pages
262 and 265.
This manual and any keystroke programs contained herein are pro-
vided “as is” and are subject to change without notice. Hewlett-
Packard Company makes no warranty of any kind with regard to
this material or the keystroke programs contained herein, includ-
ing, but not limited to, the implied warranties of merchantability
and fitness for a particular purpose. Hewlett-Packard Co. shall not
be liable for errors or for incidental or consequential damages in con-
nection with the furnishing, performance, or use of this manual or the
keystroke programs contained herein.
© Hewlett-Packard Co. 1988. All rights reserved. Reproduction, ad-
aptation, or translation of this manual, including any programs, is
prohibited without prior written permission of Hewlett-Packard Com-
pany, except as allowed under the copyright laws. Hewlett-Packard
Company grants you the right to use any program contained in this
manual in this Hewlett-Packard calculator.
The programs that control your calculator are copywrited and all
rights are reserved. Reproduction, adaptation, or translation of those
programs without prior written permission of Hewlett-Packard Co. is
also prohibitied.
Corvallis Division
1000 N.E. Circle Blvd.
Corvallis, OR 97330, U.S.A.
Printing History
Edition 1 June 1988 Mfg. No. 00042-90002Welcome to the HP-42S
Your HP-42S reflects the superior quality and attention to detail in
engineering and manufacturing that have distinguished Hewlett-
Packard products for nearly 50 years. Hewlett-Packard stands behind
this calculator: we offer accessories, worldwide service, and expertise
to support its use (see inside the back cover).
Hewlett-Packard Quality
Our calculators are made to excel, to last, and to be easy to use.
™ This calculator is designed to withstand the usual drops, vibrations,
pollutants (smog, ozone), temperature extremes, and humidity vari-
ations that it may encounter in normal, everyday worklife.
™@ The calculator and its manual have been designed and tested for
ease of use. We selected spiral binding to let the manual stay open
to any page, and we added many examples to highlight the varied
uses of this calculator.
@ Advanced materials and permanent, molded key lettering provide a
long keyboard life and a positive feel to the keyboard.
® CMOS (low-power) electronics and the liquid-crystal display allow
the HP-42S to retain data while it is off and let the batteries last a
long time.
™@ The microprocessor has been optimized for fast and reliable com-
putations. The calculator uses 15 digits internally, then rounds to
12 digits for precise results.
™@ Extensive research has created a design that has minimized the ad-
verse effects of static electricity, a potential cause of malfunctions
and data loss in calculators.
Welcome to the HP-42S 3The feature set of this calculator reflects needs and wishes we solic-
ited from customers. The HP-42S features:
@ Built-in applications:
@ A solver (root finder) that can solve for any variable in an
equation.
™ Numeric integration for calculating, definite integrals.
™ Matrix operations, including a Matrix Editor, a solver for simulta-
neous linear equations, and many other useful matrix functions.
§ Statistical operations, including curve fitting and forecasting.
™ Base conversions, integer arithmetic, and binary manipulation of
hexadecimal, decimal, octal, and binary numbers.
Complex numbers and vector functions.
Graphic display control functions.
Menus that can be customized.
The ability to run programs written for the HP-41C and HP-41CV
calculators.
™ Over 7,200 bytes of memory for storing programs and data.
® An infrared printer port for printing calculations, programs, data,
and graphics using the HP 82240A Infrared Printer.
Catalogs for reviewing and using items stored in memory.
™ An easy-to-use menu system that uses the bottom line of the dis-
play to label the top row of keys.
Reverse Polish Notation (RPN) operating logic for the most efficient
solutions to complicated problems.
Keystroke programming with branching, looping, tests, and flags.
A two-line, 22-character, alphanumeric display with adjustable
contrast.
4 Welcome to the HP-42Sy?yY).y YY) YY YY YY VDP DPDDDP DYDD DPD)Y DD? YD YD YDMenu Maps
Operation Index
Subject Index
For a good start
be sure to read chapter 1!
Part 1: Basic Operation
Part 2: Programming ~
Part 3: Built-In Applications
Part 4: Appendixes and Reference
Contents YContents
Part 1: Basic Operation
18
18
18
Getting Started
Important Preliminaries
Power On and Off; Continuous Memory
Regular and Shifted Keystrokes
Annunciators
Adjusting the Display Contrast
Using Menus
Displaying a Menu
Multirow Menus (wa)
Submenus and [EXIT
Clearing the Calculator
Using the (#) Key
The CLEAR Menu
Clearing All Programs and Data
Errors and Messages
Keying In Numbers
Making Numbers Negative
Exponents of Ten
Understanding Digit Entry
Simple Arithmetic
One-Number Functions
Two-Number Functions
Chain Calculations
Exercises: Calculations for Practice
Range of Numbers
Changing the Display Format
Number of Decimal Places
Selecting the Radix Mark (Comma vs. Period)
Showing All 12 Digits
Contents
737 ~~“ Keying In Alphanumeric Data
37 Using the ALPHA Menu
38 The Alpha Display and the Alpha Register ~
40 = Catalogs
41 An Introduction to Flags
2 42 The Automatic Memory Stack -
42 What the Stack Is o
43 The Stack and the Display
44 Reviewing the Stack ((Rt)) ~
44 Exchanging x and y ([zy]) LC
45 = Arithmetic—How the Stack Does It
46 How [ENTER] Works ~
48 = How CLX Works L
48 The LAST X Register
49 Using §§(LASTx] To Correct Mistakes ~
50 Using §§(LASTx] To Reuse Numbers
52 Chain Calculations
52 Order of Calculation ~
53 Exercises: More RPN Calculations L
3 55 Variables and Storage Registers ~
55 — Storing and Recalling Data ~
56 Variables
57 Storage Registers
58 Storing and Recalling Stack Registers ~
60 Data Types
61 = Arithmetic With (STO) and [RCL
62 Managing Variables ~
62 Clearing Variables
62 Using the Variable Catalogs ~
63 Printing Variables L
63 Managing Storage Registers
64 Changing the Number of Storage Registers (SIZE) ~
64 Clearing Storage Registers ~
64 Printing Storage Registers
65 Storing and Recalling Alpha Data ~
65 Storing Alpha Data (ASTO) =
66 Recalling Alpha Data (ARCL)
8 ContentsExecuting Functions
Using the Function Catalog
Using the CUSTOM Menu
Making CUSTOM Menu Key Assignments
Clearing CUSTOM Menu Key Assignments
Using, the [XEQ] Key
Specifying Parameters
Numeric Parameters
Alpha Parameters
Specifying Stack Registers as Parameters
Indirect Addressing—Parameters Stored Elsewhere
Exercises: Specifying Parameters
Function Preview and NULL
Numeric Functions
General Mathematical Functions
Percentages
Simple Percent
Percent Change
Trigonometry
Setting Trigonometric Modes
Trigonometric Functions
The Conversion Functions
Converting Between Degrees and Radians
Using the Hours-Minutes-Seconds Format
Coordinate Conversions (Polar, Rectangular)
Altering Parts of Numbers
Probability
The Probability Functions
Generating a Random Number
Hyperbolic Functions
Complex Numbers
Entering Complex Numbers
How Complex Numbers Are Displayed
Arithmetic With Complex Numbers
Vector Operations Using Complex Numbers
Storing Complex Numbers
Complex-Number Variables
Making the Storage Registers Complex
Contents 9Printing
Common Printing Operations
Printing Modes
Flags That Affect Printing
Printing Speed and Delay Time
Low Calculator Batteries
Calculator Functions That Print
Printing Graphics in the Display
Printing Programs
Character Sets
Part 2: Programming
10
121
121
125
128
129
130
Contents
Simple Programming
An Introduction to Keystroke Programming
Program-Entry Mode
The Program Pointer
Moving the Program Pointer
Inserting Program Lines
Deleting Program Lines
Executing Programs
Normal Execution
Running a Program With (R/S
Stopping a Program
Testing and Debugging a Program
Error Stops
The Basic Parts of a Program
Program Lines and Program Memory
Program Labels
The Body of a Program
Constants
Program ENDs
Clearing Programs
Program Input and Output
Using the INPUT Function
Using a Variable Menu
Displaying Labeled Results (VIEW)
Displaying Messages (AVIEW and PROMPT)
Entering Alpha Strings Into Programs10
11
131
131
132
132
132
134
135
135
136
136
Printing During Program Execution
Using Print Functions in Programs
Printing With VIEW and AVIEW
Working With Alpha Data
Moving Data Into and Out of the Alpha Register
Searching the Alpha Register
Manipulating Alpha Strings
Graphics
Turning On a Pixel in the Display
Drawing Lines in the Display
Building a Graphics Image Using the Alpha Register
Programming Techniques
Branching
Branching to a Label (GTO)
Calling Subroutines (XEQ and RTN)
The Programmable Menu
Local Label Searches
Global Label Searches
Conditional Functions
Flag Tests
Comparisons
Testing the Data Type
Bit Test
Looping
Looping Using Conditional Functions
Loop-Control Functions
Controlling the CUSTOM Menu
Example Programs
The Display Plot Program (“DPLOT”’)
The Printer Plot Program (“PLOT”)
Using HP-41 Programs
Important Differences
HP-41 User Keyboard
Statistical Operations
Printer Interface
The Alpha Register
Range of Numbers
Data Errors and the Real-Result Flag
The Display
Keystrokes
Contents 11171
171
175
No Packing
Function Names
Enhancing HP-41 Programs
Part 3: Built-In Applications
12
13
14
12
196
197
197
199
200
200
200
202
203
205
205
206
208
211
212
213
213
214
Contents
The Solver
Using the Solver
Step 1: Writing a Program for the Solver
Step 2: Selecting a Program To Solve
Step 3: Storing the Known Variables
Step 4: Solving for the Unknown
Choosing Initial Guesses
How the Solver Works
Halting and Restarting the Solver
Interpreting the Results
Using the Solver in a Program
More Solver Examples
The Equation of Motion for Free-Fall
The Time Value of Money Equation
Numerical Integration
Using Integration
Step 1: Writing a Program for Integration
Step 2: Selecting a Program To Integrate
Step 3: Storing the Constants
Step 4: Selecting a Variable of Integration
Step 5: Setting the Limits and Calculating the Integrat
Accuracy of Integration
Using Integration in a Program
Matrix Operations
Matrices in the HP-42S
Creating and Filling a Matrix in the X-Register
Creating and Filling a Named Matrix
The Matrix Editor
How Elements Get Stored
Matrices That Automatically Grow
Restoring the Old Value
Inserting and Deleting Rows¢
(
\
15
16
214
214
215
215
217
218
219
220
220
223
223
225
225
225
226
227
227
227
245
245
247
248
248
249
251
Complex Matrices
Creating Complex Matrices
Converting a Complex Matrix to Real
Filling a Complex Matrix
Redimensioning a Matrix
Matrix Arithmetic
Matrix Functions
Vector Operations
Simultaneous Linear Equations
Matrix Utility Functions (Indexing)
Controlling the Index Pointers
Storing and Recalling Matrix Elements
Programmable Matrix Editor Functions
Swapping Rows
Submatrices
Special Matrices in the HP-42S
The Storage Registers (REGS)
Matrices for Simultaneous Equations
Statistics
Entering Statistical Data
Statistical Functions
Sums
Mean
Weighted Mean
Standard Deviation
Correcting Mistakes
The Summation Registers
Limitations on Data Values
Using Statistical Data Stored in a Matrix
Curve Fitting and Forecasting
How Curve Fitting Works
Base Operations
Base Conversions
The Representation of Numbers
Negative Numbers
Showing Numbers
Range of Numbers
Integer Arithmetic
The Logic Functions
Programming Information
Contents 13Part 4: Appendixes and Reference
A
14
254
254
254
257
257
258
260
260
261
262
Contents
Assistance, Batteries, and Service
Obtaining Help in Operating the Calculator
Answers to Common Questions
Power and Batteries
Low-Power Indications
Installing Batteries
Environmental Limits
Determining if the Calculator Requires Service
Confirming Calculator Operation—the Self-Test
Limited One-Year Warranty
What Is Covered
What Is Not Covered
Consumer Transactions in the United Kingdom
If the Calculator Requires Service
Obtaining Service
Service Charge
Shipping Instructions
Warranty on Service
Service Agreements
Radio Frequency Interference
Managing Calculator Memory
Resetting the Calculator
Clearing All Memory
Reclaiming Memory
How the HP-42S Conserves Memory
What Happens When Data Is Copied
Writing Memory-Efficient Programs
Memory Organization
Flags
User Flags (00 Through 10 and 81 Through 99)
Control Flags (11 Through 35)
System Flags (36 Through 80)
Flags That Represent Options
Flags That Represent Conditions
Summary of HP-42S Flags283
292
310
336
Character Table
Operation Index
Subject Index
ContentsDIIIIIIIIIINAIIIIIIIIIIIIDD DPart 1
Basic Operation
Page 18
42
55
67
77
90
100
1: Getting Started
2: The Automatic Memory Stack
3: Variables and Storage Registers
4: Executing Functions
5: Numeric Functions
6: Complex Numbers
7: Printing1
Getting Started
This chapter provides you with a detailed orientation to the HP-42S.
You'll learn how to:
Use menus to access calculator functions.
Clear information from calculator memory.
Key in numbers and do arithmetic.
Change the way numbers are displayed.
Key in alphanumeric data with the ALPHA menu.
Use catalogs to review the contents of calculator memory.
Important Preliminaries
Power On and Off; Continuous Memory
To turn on the HP-42S, press [Exit]. Notice that ON is printed below
the key.
To turn the calculator off, press §§(OFF]. That is, press and release the
shift key, §§, then press [EXIT] (which has OFF printed above it). Since
the calculator has Continuous Memory, turning it off does not affect
any information you've stored.
After about 10 minutes of inactivity, the calculator turns itself off to
conserve battery power. When you turn the calculator on again, you
can resume working right where you left off.
18 1: Getting StartedUnder most conditions, calculator batteries last well over a year. If
you see the low-battery symbol ((==)) in the display, replace the bat-
teries as soon as possible. Refer to appendix A for details and
instructions.
Regular and Shifted Keystrokes
Each key has two functions: one printed on its face, and a shifted
function printed in color above the key. For example, OFF is the
shifted function of the [EXIT] key (written as —§[OFF]). To execute a
shifted function, press ff, then press the key.
Pressing (J turns on the shift annunciator (_4#), which remains on
until you press the next key. To cancel _#, just press J again.
The __# remains active for as long as you hold down the key. To
execute several consecutive shifted functions, hold J down and press
the appropriate keys.
Annunciators
The calculator uses seven annunciators at the top of the display to
indicate various conditions.
Annunciators
—o
VA —+ om. (+) (GRAD
Cursor
Menu labels
1: Getting Started 19Annunciator Meaning
The (¥] and [4] keys are active for moving through a
multirow menu (page 23).
Shift (M§) is active.
The calculator is sending information to the printer (page
100).
The calculator is busy executing a function or a program.
Battery power is low.
Radians angular mode is set (page 80).
Grads angular mode is set (page 80).
Adjusting the Display Contrast
To adjust the contrast of the display for various viewing angles and
lighting conditions:
1. Press and hold (Exit).
2. Press [+] to darken the display, [=] to lighten the display.
3. Release [EXIT].
You can use this sequence at any time without disrupting any other
calculator operation.
The top row of keys is very special. In addition to the standard func-
tions printed on the keyboard, these six keys can be redefined by
menu labels in the display. To execute a function in a menu, press the
key directly below the corresponding menu label.
20 1: Getting Starteda2s RPN SCIENTIFIC
fe [PERM] ON! [Gatd | RAN |
TTT
Menu labels
Example: Using a Menu. Use the N! (factorial) function in the menu
shown above to calculate the factorial of 5 (that is, 5!). Key in 5 and
display the PROB (probability) menu.
5 @(Proe) ie 5. 0000
TS SL ST TT
To execute the N! function, press the key directly below the menu
label ([Zz]). This is written as:
Ae ly: @, 6668
x: 126.6800
Thus, 5! = 120.
Displaying a Menu
Notice that some of the shifted functions are printed on the keyboard
in shaded boxes. These are keys that select menus. When you select a
menu with one of these keys, the first row of the menu is immedi-
ately displayed.
Application Menus. There are five menu-driven applications in the
HP-42S. (See the illustration below.) Application menus have top pri-
ority among all of the menus. To exit from an application, press (EXIT
or select another application.
Function Menus. The HP-42S has over 350 built-in functions. The
most frequently used functions are grouped into function menus. In
the example above, you used a function menu ({f§[PROB)) to execute
the N! function.
1: Getting Started 21If you select a function menu while in an application, the calculator
remembers the application menu and displays it again when you exit
the function menu.
Application Function
Menus: Menus:
BASE CATLOG
No Menu oe Kes MATRIX Menu Key CLEAR
ExiT} SOLVER Exit) CONVERT
STAT CUSTOM
Sfx) DISP .
Menu Key
No Menu
EXIT
Disabling Automatic Exit. Function menus automatically exit as
soon as you execute one of the functions in the menu. If you want to
use a function menu repeatedly, you can disable automatic exiting by
selecting the menu twice. For example, if you press J[PROB) (PROB),
the PROB menu stays in the display until you press [EXIT] or select
another menu.
Menu Labels Marked With “a”. There are a variety of modes and
settings in the HP-42S. If a menu label contains the ™ character, then
that mode or setting is currently selected. For example, display the
MODES menu:
MMovEs)
The menu in this display shows that Degrees (§5EGH) and Rectangu-
lar (REG) modes are selected. (These modes are explained in
chapter 5.)
The ALPHA Menu. The ALPHA menu ( is neither an
application nor a function menu. It is an extension of the keyboard
that allows you to type characters (alphabetic and others) that don’t
appear on the keyboard. Instructions for using the ALPHA menu are
on page 37.
22 1: Getting StartedCC é¢
¢
€CECEECECCEEEECE € E
( ¢ ¢
(€ €€ ¢
¢
The TOP.FCN Menu. Pressing §§[TOP.FCN) (top-row functions) dis-
plays a menu containing the functions (shifted and unshifted) on the
six top-row keys:
=— y x 10% e GTO
(2+) G7x) Ge) (L0G) (LN) (KEa
Use the TOP.FCN menu when you want to use one of these functions
without exiting from the current application menu.
Multirow Menus (va)
Menus with more than six labels are divided into rows. If a menu has
more than one row, the wa annunciator appears, indicating that the
Y) and (4) keys can be used to display the other rows.
For example, the CLEAR menu has two rows. Press to see
the first row:
Press [¥] to display the second row:
Because menus are circular, pressing [¥] again returns to the first row.
Submenus and (EXIT
Some menu keys lead to other menus, called nested menus or
submenus. The menu map below shows:
@ Pressing §§[PGMFCN] displays the first of four rows in the
PGM.FCN menu.
™ Pressing (¥] or (4) displays the next or previous row (va is
displayed).
@ Pressing [X?@l or |RP¥H displays a corresponding submenu.
@ Pressing (EXIT) exits the current menu. If it is a submenu, then the
previous menu is displayed.
1: Getting Started 23—— — fxn) = [xi
1: Getting Started
24Example: Displaying the X?0 Submenu. Display the second row
of the PGM.FCN menu.
WPauEN)
v
Now display the X?0 submenu.
R98 fx: 126.8006
| Ee ed ERE
When you exit the submenu, the calculator displays the second row of
PGM.FCN again.
EXIT x: 120. 8006
eT EE CT |
Press [EXIT] again and the PGM.FCN menu disappears.
EXIT, fy: 8, 8868
be 126.0080
Clearing the Calculator
There are several ways to clear information from the calculator. You
can clear characters, numbers, variables, programs, or even all of cal-
culator memory with a single operation.
Using the [4] Key
The [@) key is a backspace and delete key. The calculator’s response
when you press (@] depends on what is in the display.
@ If a cursor is present (_), [@) backspaces and deletes the preceding
digit or character.
@ If a message is displayed, [4] clears the message.
@ If a number (or other data) is displayed without a cursor, (4) clears
the entire number to zero.
@ If program lines are displayed, (€) deletes the current program line.
(Program-entry mode is explained in chapter 8.)
1: Getting Started 25The CLEAR Menu
The CLEAR menu contains 12 functions for clearing information from
the calculator.
HB(CLEAR}- (QEEH Clear statistics.
RBBB Clear program.
Qe Clear variable.
GBS Clear stack.
QR Clear Alpha register.
BER Clear X-register to zero.
wa
§EQRG Clear storage registers.
@QEBB Delete program lines.
MGR CClear keys.
(Be CClear liquid crystal display.
(QQMBE Clear MENU.
(SEB Clear all programs and
data.
Clearing All Programs and Data
The CLALL (clear all) function clears all programs and data from cal-
culator memory but leaves display formats and other settings intact.
1. Press §§(CLEAR) (¥) SRE .
2. Press (ES to confirm; or any other key to cancel.
A special key sequence can be used to clear all of memory (including
modes and flags). Refer to “Clearing All Memory” in appendix B.
26 1: Getting StartedErrors and Messages
Whenever you attempt an operation that the calculator cannot com-
plete, it displays a message that specifies the problem. If you're not
sure what you’ve done wrong, refer to appendix D, “Messages.”
You do not have to clear the message to continue working—the mes-
sage disappears as soon as you press a key. If you want to clear the
message without altering anything else, press (€).
Keying In Numbers
If you make a mistake while keying in a number, press (] to back-
space and delete the last digit, or press §§(CLEAR) MRMBMJ (clear X-
register) to clear the entire number.
Making Numbers Negative
The GZ) (change sign) key changes the sign of a number.
@ To key in a negative number, type the number, then press (74).
@ To change the sign of a number already displayed, just press FA).
Exponents of Ten
Numbers with exponents of ten are shown in the display with an € to
separate the nonexponent part of the number from the exponent. A
number too large or too small for the current display format is auto-
matically displayed in exponential form. For example, the number
123,000,000,000,000 (1.23 x 10'4) is displayed as 1. 2300614.
To key in a number with an exponent:
1. Key in the nonexponent part of the number. If this part is nega-
tive, press FZ).
2. Press [E]. Notice that the cursor follows the &.
4: Getting Started 273. Key in the exponent. If it is negative, press (4). The largest pos-
sible exponent you can key in is +499 (with one digit to the left
of the decimal point).
For example, to key in Planck’s constant, 6.6262 x 10-54, you would
press: 6.6262 (E] 34 ().
For a power of ten without a multiplier, such as 10°4, just press [E] 34.
The calculator automatically inserts a “1” before the exponent: 1£34_.
Other Exponent Functions. To specify an exponent of ten while en-
tering a number, use (E). To calculate an exponent of ten (the base 10
antilogarithm), use §§(10*). To calculate the result of any number
raised to a power, use {§(*). Numeric functions (including §§(0*) and
WY) are covered in chapter 5.
Understanding Digit Entry
As you key in a number, the cursor (_) appears in the display. The
cursor shows you where the next digit will go and indicates that the
number is not completed yet. That is, when a cursor is present, digit
entry is not terminated.
@ If digit entry is not terminated, then (€) backspaces to erase the last
digit.
™ If digit entry is terminated (no cursor), then [4] clears the entire
number (which is equivalent to
Simple Arithmetic
All numeric functions follow one simple rule: when you press a func-
tion key, the calculator immediately executes the function. Therefore, all
operands must be present before you execute a function.
Arithmetic can be broken down into two types of functions: one-
number functions (such as square root) and two-number functions
(such as addition).
28 1: Getting StartedCC € €
f(€ €€ EC CECEEE C
(CC € ¢
(
¢
Many of the displays shown in this manual assume that
you've worked the preceding example. Unless indicated
Note otherwise, previous results and the contents of your cal-
culator are irrelevant to the current example.
One-Number Functions
One-number functions operate on the the value in the display
(x: value). To use a one-number function:
4. Key in the number. (If the number is already displayed, you can
skip this step.)
2. Press the function key. (The function may be on a normal or
shifted key or in a menu.)
For example, to calculate %2, key in 32 ...
32 fr: 126. 9888
x: S2_
... then press the function key:
fy: 120, 8960
pe: 8.9313
The result (to four decimal places) is 0.0313.
Now calculate 1.5129 .
1.5129
If a number is already in the display, you don’t have to key it in
again. Calculate the square of 1.23.
; 8.88
a ye 151
Remember, you can make a number negative at any time with the []
key. Notice that only the number in the bottom line changes.
1: Getting Started 29A)
9313
25129
fy:
ES
One-number functions also include the logarithmic functions, the
trigonometric functions, the parts-of-numbers functions, and the hy-
perbolic functions; they are covered in chapter 5.
Two-Number Functions
To use a two-number function (such as ©, GB), or &):
1. Key in the first number.
2. Press [ENTER] to separate the first number from the second.
3. Key in the second number. (Do not press [ENTER] again.)
4. Press the function key.
Remember, both numbers must be present before executing the function.
For example:
To Calculate: Press: Result:
12+ 3 12 (ENTER) 3 & 15.6660
12-3 12 (ENTER) 3 (= 9,8088
12 x 3 12 (ENTER) 3 [x 36.9000
12 + 3 12 (ENTER) 3 (= 4.0908
The order of entry is essential for noncommutative functions (such as
© and (¢)). If the numbers have been entered in the wrong order,
you can still get the correct answer without reentering the numbers.
Swap the order of the numbers by pressing [xy] (x exchange y), then
perform the intended function. (Refer also to “Exchanging x and y’ in
chapter 2.)
30 1: Getting StartedCCC E €
(
(
Chain Calculations
The speed and simplicity of calculating with the HP-42S is apparent
during chain calculations (calculations with more than one operation).
Even during the longest of calculations, you still work with only one or
two numbers at a time—the automatic memory stack stores intermedi-
ate results until you need them. (The stack is explained in chapter 2.)
The process of working through a problem is the same as working it
out on paper, but the calculator does the hard part.
Example: A Chain Calculation. Solve (12 + 3) x 7. To work this
problem on paper, you would first calculate the intermediate result of
(12 + 3). That is, you would start inside the parentheses and work
outward.
15
(12-3) x 7
Then you would multiply the intermediate result by 7 to get the final
answer.
15 x 7 = 105
Solving the problem on the HP-42S uses the same logic. Start inside
the parentheses:
12 [ENTER] 3 4) ve 420083,
ta .
This intermediate result is saved automatically—you don’t need to
press (ENTER). Simply multiply it by seven.
7k lv: 4.0880
bx: 165.008
Example: Another Chain Calculation. Problems that have multiple
parentheses can be solved in the same simple manner because inter-
mediate results are automatically remembered. For example, to solve
(2 + 3) x (4 + 5) on paper, you would first calculate the values
inside parentheses, and then you would multiply them together.
5 x 9
(23) x (4-45)
1: Getting Started 31Again, working the problem on the HP-42S involves the same logical
steps:
2 (ENTER) 3 (+ ly: 165.6008
x: 5. 8888
4 (ENTER) 5 (+
Notice that the two intermediate results in the display are the same
ones you calculated on paper. Press [x] to multiply them.
x ly: 195.6000
x: 45. 0088
Remember: This method of entering numbers, called Reverse Polish
Notation (RPN), is unambiguous and therefore does not need paren-
theses. It has the following advantages:
@ You never work with more than two numbers at a time.
@ Pressing a function key immediately executes that function so there
is no need for an (=) key.
™ Intermediate results appear as they are calculated, so you can check
each step as you go.
™ Intermediate results are automatically stored. They reappear as
they are needed for the calculation—the last result stored is the
first to come back out.
™ You can calculate in the same order as you would with pencil and
paper.
@ If you make a mistake during a complicated calculation, you don’t
have to start over. (Correcting mistakes is covered in chapter 2.)
® Calculations with other types of data (such as complex numbers
and matrices) follow the same rules.
™ Calculations in programs follow the same steps as when you exe-
cute them manually.
32 1: Getting Startedé
(
Exercises: Calculations for Practice
The following calculations exercise the methods you’ve learned for
simple arithmetic. Work each problem in the same order as you would
work it on paper. (There may be more than one way to work each
problem.) Remember, use [ENTER] only for separating two numbers
entered sequentially.
Calculate: (2 + 3) + 10
Answer: 0.5000
A Solution: 2 (ENTER) 3 [+] 10
Calculate: 2 + (3 + 10)
Answer: 0.1538
A Solution: 3 [ENTER] 10 (+) 2 Ge) )
Another Solution: 2 (ENTER) 3 (ENTER) 10 (4) &
Calculate: (14 + 7+ 3-—2)+4
Answer: 5.5000
A Solution: 14 (EnTeR] 7G)3G) 204
Calculate: 4 + (14 + (7 x 3) — 2)
Answer: 0.1212
A Solution: 7 (Enter) 30 14G) 20) 4G)
Another Solution: 4 (ENTER) 14 (ENTER) 7 (ENTER) 30) G) 20) E
Range of Numbers
The HP-42S is capable of representing numbers as large as
9.99999999999 x 10499 and as small as 1 x 10~4%. If you attempt
to execute a function that returns a result larger than 9.99999999999
x 104%, the calculator displays the Qut of Range error message.
The operation you attempted is ignored, and the message disappears
when you press the next key.
If you attempt an arithmetic function that returns a number whose
magnitude is smaller than 1 x 10-49, the calculator automatically
substitutes the number zero.
1: Getting Started 33Changing the Display Format
Internally, the HP-42S always saves numbers with full 12-digit accu-
racy plus a three-digit exponent of ten.
Even though numbers are stored with full precision, the way they're
displayed depends on the current display format. There are two gen-
eral ways to display numbers:
™ Round the number to a specified number of digits. There are three
formats that do this: FIX (fixed-decimal notation), SCI (scientific nota-
tion), and ENG (engineering notation).
® Show all of the digits in a number (except trailing zeros). This is the
ALL format.
In addition to controlling how digits are displayed, you can select the
character used as the decimal point—called the radix. The radix may
be a period (default) or a comma.
Functions for changing the display format are in the DISP (display)
menu:
lose Fixed-decimal notation.
Scientific notation.
Engineering notation.
All notation.
Radix period.
Radix comma.
Number of Decimal Places
The default display format is FIX 4. (The calculator displays numbers
rounded to four places to the right of the decimal.)
34 1: Getting StartedTo change the number of decimal places:
1. Press §§(DisP).
2. Press: ES, SG . ERE. or ERE
3. For FIX, SCI, and ENG, specify the number of digits (0 through
11):
@ Key in two digits (such as 02).
™ Or, key in a single digit followed by [ENTER] (such as 2
ENTER }).
Example: Changing the Display Format. Key in the numbers
2.46 x 10” and 1234567.89, and then change the display format to
ENG 2.
2.46 (E) 7 [ENTER] 1234567.89 ly: 24, 600, O00. DODO
be: 1, 234,567. 89_
@loisp) 2 (ENTER : 24,686
—_
Now change to the ALL display format.
OS) Ba, 600,000
a i: 15334, 567.89
Now return to the default setting (FIX 4).
DISP } (URW 4 CENTER] : 24,608,080, 0000
. he 1,284,507. 8900
Fixed-Decimal Notation (FIX). In FIX notation, the calculator dis-
plays numbers rounded to the specified number of decimal places.
Exponents of 10 are used only if the number is too large or too small
to display using the current display format. (Example: 3, 1416.)
Scientific Notation (SCI). In SCI notation, the calculator displays
numbers with one digit to the left of the decimal point and the speci-
fied number of digits to the right. An exponent of 10 is always
shown; even if it is zero. (Example: 6. @228€ 26.)
1: Getting Started 35Engineering Notation (ENG). In ENG notation, the calculator dis-
plays numbers in a format similar to SCI except the exponent of 10 is
always a multiple of three. This means that more than one digit may
appear to the left of the decimal point. The number of digits you
specify indicates how many digits to display after the first digit. (Ex-
ample:
[email protected]€-3.)
All Notation (ALL). In ALL notation, the calculator displays numbers
using full precision. That is, all significant digits to the right of the
decimal point are shown. (Example: 4. 17359249.)
Selecting the Radix Mark (Comma vs. Period)
. When
To change the radix mark to a comma, press
the radix is a comma, periods are used to separate digits.
1.234,.567,8900
To change the decimal point back to a period, press (0's?) peo.
1,234,567.8988
You can remove the digit separators by clearing flag 29 (page 276).
Showing All 12 Digits
When you press and hold the [SHOW] key, the calculator displays
the contents of the X-register using the ALL format—that is, all sig-
nificant digits are shown. When you release the key, the display
returns to the current display format.
1.23456789012 (ENTER lv: 1.2346
x: 1.2346
(SHOW) (hold down) 1. 23456789012
ly: 1.2346
ix: 1.2346
(release)
The (§§(SHOW] key can also be used to show the entire contents of the
Alpha register (page 40), a long program line (page 111), or the first
element in a matrix (page 207).
36 1: Getting Started€€E€CECEEEECEECE CEE
(
Cf£ € €¢
(
Keying In Alphanumeric Data
Alphabetic and other characters are typed into the HP-42S using the
ALPHA menu, which contains all the letters in the alphabet (upper-
case and lowercase) and many other characters.
One or more characters typed with the ALPHA menu form an Alpha
string.
Using the ALPHA Menu
To type a string of characters into the Alpha register:
1. Press [ALPHA] to select the ALPHA menu.
2. Press an ALPHA menu key to select a group of letters or
characters.
3. Press a menu key to type a character. To type a lowercase letter,
press J before typing the letter.
Repeat steps 2 and 3 for each letter or character. You can also use the
following Keys to type Alpha characters: §(%), @=), £), @),G.E
+), 0), 0, 2), @), @, &, ©), @, @, @), and GF).
Example. The keystrokes for typing the string The HP-42S. are:
SACHA) RSTO A BB (old down) CHT RR RBOOE! NEN
(release @§) X20 ! LECH ERHEE Gore! Same (-] (4) 2
Rstuy sual C)
For simplicity, this manual shows these keystrokes as:
(B(ALPHA] The HP—42S.
ALPHA Typing Tips:
™ Any blank menu key in the ALPHA menu can be used to type a
space character. A rapid sequence for typing a space is [KEQ] [XEQ
(that is S29 [A or HAESCY |).
@ To type several lowercase letters, hold down the shift key (fj) while
typing.
1: Getting Started 37GBCALPHA
The characters in each of the submenus are shown in the menu maps
beginning on page 292.
The Alpha Display and the Alpha Register
Alpha strings can be typed only when the ALPHA menu is displayed.
How strings are used or where they are stored, however, depends on
other circumstances. Alpha strings can be:
™ Typed directly into the Alpha register.
™ Used as a function parameter to specify a variable name or pro-
gram label (page 73).
™ Entered as program instructions (page 130).
Alpha Mode: Entering Characters Into the Alpha Register. In
the previous example, the Alpha characters were entered into the Al-
pha register. When you press , the calculator displays the
ALPHA menu and the Alpha register—this is Alpha mode.
38 «1: Getting Startedi
(
(
If there are characters in the Alpha register, they are displayed when
you enter Alpha mode. The Alpha register is cleared when you begin
typing. To append characters to the current contents of Alpha, press
[ENTER] to turn the cursor on before you begin to type.
The following illustration shows the keys that are active in Alpha
mode.
CA eacicxao
a2s RRPN SCIENTIFIC
Va —t em +) GRAD
The HP-42S. _
aa EL A Ce
ARCL.
ASTO
NIRG9000
oHoo00g
Capacity of the Alpha Register. The Alpha register can hold up to
44 characters. The calculator beeps when the Alpha register gets full.
The beep warns you that each additional character you type will push
the first (left-most) character out of the Alpha register.
1: Getting Started 39If the display overflows, the .. character indicates there are some
characters you can’t see.
To display the entire Alpha register:
@ While in Alpha mode, press and hold §§([SHOW).
® While not in Alpha mode, press §§(PGM.FCN) MINE (Alpha view).
Printing the Alpha Register. To print the contents of the Alpha
register, press iT] RREM! (print Alpha). For more information on
printing, refer to chapter 7.
Catalogs
Catalogs are used to view the contents of calculator memory. You can
also use a catalog to execute functions or programs or recall variables.
a Functions.
Programs.
Real variables.
Complex variables.
Matrix variables.
Memory available.
To display the amount of available memory, press and hold the
(GHEMM key. The calculator displays a message like this:
Available Memory
6836 Bytes
The message disappears when you release the key.
40 = 1: Getting Started(
(
¢
(€CECECECE ECE €
€ ¢
( ¢
(
An Introduction to Flags
Throughout the rest of this manual there are references to numbered
flags. A flag has two states, set and clear. If you are unfamiliar with
flags, simply think of them as switches that are either on or off.
The HP-42S has 100 flags (numbered 00-99); most of them have spe-
cial purposes inside the calculator. To set, clear, and test the status of
flags, use the functions in the FLAGS menu:
@lFucs Set flag.
Clear flag.
Flag set test.
Flag clear test.
Flag set test and clear.
Flag clear test and clear.
For more information on flags, refer to appendix C.
1: Getting Started 41The Automatic
Memory Stack
This chapter explains how calculations take place in Hewlett-
Packard’s automatic memory stack and how it minimizes the number
of keystrokes required to do complicated calculations.
More specifically, you will learn:
@ What the stack is.
= How the stack automatically remembers results from previous
calculations.
™ What is meant by stack lift and stack drop.
@ How to view and manipulate the contents of the stack.
® How to save keystrokes and correct mistakes with [|
You do not need to read and understand this chapter to use the HP-42S.
However, you'll find that understanding this material will greatly en-
hance your use of the calculator. In programs, efficient use of the
stack saves memory by reducing the number of program steps needed
to solve a problem.
What the Stack Is
Automatic storage of intermediate results is the reason the HP-42S eas-
ily processes complex calculations, and does so without parentheses.
The key to automatic storage is the automatic, RPN memory stack.*
* HP’s operating logic is based on a mathematical logic known as “Polish Notation,” devel-
oped by the Polish logician Jan Lukasiewicz. (1878—1956). While conventional algebraic
notation places the operators between the relevant numbers or variables, Lukasiewicz’s nota-
tion places them before the numbers or variables. For optimal efficiency of the stack, we
have modified that notation to specify the operators after the numbers. Hence the term
Reverse Polish Notation, or RPN.
42 2: The Automatic Memory Stack¢
(
€€€ CEE fC
(
¢
The stack consists of four storage locations, called registers, which are
“stacked” on top of each other. It is a work area for calculations. These
registers—labeled X, Y, Z, and T—store and manipulate four current
numbers. The “oldest” number is the one in the T-register (top).
The most “recent” number is in the X-register and is usually displayed.
You might have noticed that several functions’ names include an x or y.
These letters refer to the values in the X- and Y-registers. For example,
§§(*) raises the number in the Y-register to the power of the number in
the X-register.
To clear all four of the stack registers to zero, press (CLEAR) SEES .
Pe] Each stack register can hold any type of data (a real num-
ber, Alpha string, complex number, or matrix). Examples in
Note this chapter use real numbers; however, the stack works the
same regardless of the type of data it contains.
The Stack and the Display
Since the HP-42S has a two-line display, it is capable of displaying two
numbers (x and y) or one number (x) and a menu.
2: The Automatic Memory Stack 43Reviewing the Stack ([R+
Pe a a
The [Re] (roll down) key lets you review the entire contents of the
stack by “rolling” the contents downward, one register at a time.
Suppose the stack is filled with 1, 2, 3, 4 (press 1 [ENTER] 2 [ENTER] 3
ENTER) 4). Pressing (R+) four times rolls the numbers all the way
around and back to where they started:
2 1
4 3 2
1 4 3
x
. If ABC already exists, press
+7 are
STO) [ENTER] ABC [ENTER
To recall data from a variable:
1.
Press (RCL).
2. Select the variable from the catalog, or type the variable name
using the ALPHA menu. (Refer
to step 2 above.)
* Instructions for using the ALPHA menu are on page 37.
3: Variables and Storage RegistersCC ECC ECE
(
For example, to recall a copy of the data in the variable DATA1, press
RCL) HATAM (assuming DATA] already exists).
DATA1
Storage Registers
Storage registers are numbered storage locations that each hold a sin-
gle number. Initially, the HP-42S has 25 storage registers (designated
Roo-Ro4), each containing a zero. You can change the number of stor-
age registers with the SIZE function (page 64).
To store data into a storage register:
1. Press (STO).
2. Key in the register number: two digits or a single digit followed
by (ENTER). Data previously stored in the register is overwritten
with the new data.
For example, to store a copy of the number in the X-register into Roz,
press (STO) 02 or (STO) 2 (ENTER).
ZREG Register number.* -
CLY, DIM, EDITN, - Variable name.
INDEX, INTEG, MVAR,
PRV, SOLVE
CF, FC?, FC?C, FS?, | Flag number. -
FS?C, SF
ENG, FIX, SCI Number of digits. -
GTO, LBLt Numeric program label. | Alpha program label.
XEQ Numeric program label. | Function name or
Alpha program label.
CLP,t PGMINT, - Alpha program label.
PGMSLY, PRPt
* Functions that accept register numbers also accept stack registers as parameters. Refer to
“Specifying Stack Registers as Parameters” below.
t Indirect addressing cannot be used with this function.
4: Executing Functions 71Functions That Require One Parameter (Continued)
DEL,t LiSTt Number of program
lines.
sizet Number of storage
registers.
TONE Tone number.
* Functions that accept register numbers also accept stack registers as parameters. Refer to
“Specifying Stack Registers as Parameters” below.
+ Indirect addressing cannot be used with this function.
Functions That Require Two Parameters
ASSIGN Function name, Alpha Key number (01
program label, or vari- | through 18).t
able name.t
KEYG, KEYX
global).
Numeric Parameters
Functions that accept numeric parameters display a cursor for each
digit expected. For example, the (EMIH function prompts you with
FIX __, which takes two digits.
To complete an instruction with a numeric parameter:
@ Key a digit for each position marked by a cursor. Include leading
zeros if there are any.
@ Or, key in fewer digits and complete the function by pressing
ENTER).
For example, you can set the SIZE to 9 storage registers by pressing
QCMODES) (7) BEER followed by 9 [ENTER] or 0009.
72 4: Executing Functions(
Alpha Parameters
If the function accepts Alpha parameters, you can select the ALPHA
menu by pressing [ENTER] or [ALPHA]. After typing the parameter,
press [ENTER] or [ALPHA] to complete the instruction. Digits typed
while the ALPHA menu is displayed are treated as Alpha characters.
Many functions that take Alpha parameters automatically display an
appropriate catalog menu. If the parameter you need already exists,
select it by pressing the corresponding menu key.
For example, when you execute [STO] the calculator displays a catalog
of all variables currently stored in the calculator. If there are more
than six entries in the catalog, the wa annunciator indicates that you
can use (¥] and (4) to display the additional rows of the catalog menu.
Specifying Stack Registers as Parameters
Any function that uses a numbered storage register can also access
any of the stack registers (X, Y, Z, T, and LAST X).
To specify a stack register as a parameter:
1. Execute the function. (For example, press [STO]).)
2. Press (-).
3. Specify which register you want to address:
@ Sree for the LAST X register.
@ (SPORE for the X-register.
@ (STGE for the Y-register.
@ §S7§Sy for the Z-register.
© (SER for the T-register.
Refer to page 59 for examples using stack parameters.
4: Executing Functions 73Indirect Addressing—Parameters Stored Elsewhere
Parameters for many functions can be specified using indirect address-
ing. That is, rather than entering the parameter itself as part of the
instruction, you supply the variable, storage register, or stack register
that contains the actual parameter.
Indirect addressing is particularly useful in programs when the pa-
rameter for a function is calculated.
To specify a parameter using indirect addressing:
1. Execute the function.
2. Press (-}. If the calculator displays IND __ after the function
name, skip to step 4.
3. Press (GEHDR .
4. Specify where the actual parameter is located:
@ Ina variable. Press a menu key to select the variable (the real-
variable catalog is automatically displayed if there are any real
variables) or type the name of the variable using the ALPHA
menu.
@ In a storage register. Key in the register number (two digits or a
single digit followed by [ENTER]).
@ In a stack register. Press ©) followed by §ST8G8, (STNRY,
STR], STZ], or ESET.
r ‘Alpha parameters specified indirectly are limited to six
characters because Alpha strings stored in variables and
Note registers are limited to six characters.
Example: Indirect Addressing Using a Variable. Store 3 into ABC.
Then store V7 in Ro using indirect addressing.
3 (STO ABC ly: 3.9886
>: 3. 6688
7 ie iv: 3.8688
a) pe: 2.6458
74 4: Executing FunctionsSTO
RCL
“] IND) SABO! 3. 008
be: 216458
To see that the instruction was successful, recall the contents of Ro3.
03 lv: 2.6458
x: 2.6458
Exercises: Specifying Parameters
Task: Set the display format to two decimal places.
Keystrokes: (§(0!SP) MEERm 02
Task: Set the display format to engineering notation using the num-
ber of digits specified in the X-register.
Keystrokes: §(0/S?) BeNem () C) Eee
Task: Store a copy of the X-register into the variable or storage regis-
ter specified in the Y-register.
Keystrokes: (S70) |) NON () ISTE
Task: Copy the first six characters of the Alpha register into the X-
register. (In Alpha mode, the [STO] key executes the ASTO function.)
Keystrokes: (§[ALPHA] (ASTO) () SSE
Task: Append a copy of the data in the T-register to the contents of
the Alpha register. (In Alpha mode, the [RCL] key executes the ARCL
function.)
Keystrokes: §§[ALPHA) (ARCL) () SS
Task: Test the flag specified by the number in the variable F (assum-
ing F already exists).
Keystrokes: M§[FLAGS) Sirsa () SER
4: Executing Functions 75Function Preview and NULL
When you hold down a key that executes a function, the name of the
function is displayed. This is a preview of the function.
If you hold the key down for about a second, the word NULL replaces
the function name in the display and the function is not executed. If
you release the key before NULL is displayed, the instruction is
executed.
For example, press and hold the [TAN] key.
TAN] (hold down)
NULL
x: 2.6458
Xo
a
rer] [wz
a
-
a
oO
The NULL message remains in the display until you release the key
and the TAN function is not executed.
: 2.6458
(release) : 2.6458
¥s
You can preview instructions that include parameters by holding
down the last key in the sequence that executes the instruction.
15 (STO) 02 (hold down the (2) key) ISTO 62
x: 15.6008
¥Z]
"sé
ae
ar]
9
S
8
9S
(release) Xk: 78°00
=
Since the instruction was aborted, the data in Rg was not
overwritten.
76 4: Executing Functions5
Numeric Functions
Most of the functions built into the HP-42S are for numeric calcula-
tions. This chapter describes numeric functions for:
™ General mathematics.
™ Percent and percent change.
@ Trigonometric calculations and conversions.
@ Altering parts of numbers.
® Probability.
@ Hyperbolics.
Many of the functions presented in this chapter do not appear on the
HP-42S keyboard. The preceding chapter, “Executing Functions,” de-
scribes how to execute functions that are not on the keyboard or in a
menu.
Remember, there are two types of numeric functions:
@ One-number functions, which replace the number in the X-register
with a result (page 29).
™ Two-number functions, which replace the numbers in the X- and Y-
registers with a result and drop the stack (page 30).
General Mathematical Functions
The following table summarizes the general mathematical functions
on the HP-42S keyboard. The Alpha name for each function is dis-
played when you hold down the key or when the function is entered
into a program.
5: Numeric Functions 77One-Number Functions
Negative of x.
Reciprocal of x.
Square root of x.
Square of x.
Common logarithm of x.
Common exponential of x.
Natural logarithm of x.
Natural exponential of x.
Sum of x and y (x + y).
Difference of x and y (y — x).
Product of x and y (x x y).
Quotient of x and y (y + x).
y to the x (y”).
Example: Calculating a Cube Root. Calculate V/14 . Since this can
be expressed as an exponent (14”), use the §§5*) function.
14 (ENTER) 3
1x
ao)
The cube root of 14 is 2.4101 (to four decimal places).
78 5: Numeric FunctionsPercentages
The percentage functions are special two-number functions because,
unlike other two-number functions, the stack does not drop when the
result is returned to the X-register.
Simple Percent
The percent function ({§[%)) calculates x% of y. For example, to cal-
culate 12% of 300:
300 (ENTER) 12 ML fy: 300. 0608
x: 36.6868
Since the original value is preserved in the Y-register, you can easily
calculate another percentage of the same number. Clear the X-register
and calculate 25% of 300.
4) 25 Be
ly: 388.9008
73.0068
The preservation of the y-value is also useful if you want to add it to
the calculated percentage.
+
lv: 2.4181
x: 375.6008
This result is 300 plus 25% of 300 (or 125% of 300).
Percent Change
The %CH (percent change) function calculates the percentage of
change from y to x.
Example: Calculating a Percent Change. The cost of blouses at
Sonja’s Boutique recently rose from $24.99 to $26.99. What was the
percentage increase?
24.99 [ENTER] 26.99
24.9988
26.99.
g
Ix:
5: Numeric Functions 739(B(CATALOG) ea
The price increased slightly more than 8%.
Trigonometry
Setting Trigonometric Modes
The first row of the MODES menu (J[MODES}) shows two sets of
modes:
@ The angular mode tells the HP-42S what unit of measure to assume
for numbers used with trigonometric functions.
360 degrees = 2x radians = 400 grads
@ The coordinate mode indicates how complex numbers are dis-
played—rectangular or polar notation. Refer to chapter 6 for a
complete description of complex numbers.
To change a mode, press the corresponding menu key.
Wilvones Degrees (no annunciator).*
Radians (RAD annunciator).
Grads (GRAD annunciator).
Rectangular.*
Polar.
Trigonometric Functions
To calculate the sine, cosine, or tangent of an angle, use the trigono-
metric functions on the keyboard. For example, to calculate the sine of
30°, press 30 (SIN).
* Default setting.
80 = 5: Numeric Functionsc
(
€€ CC € ¢
(
(
To calculate an angle, use the inverse trigonometric functions on the
keyboard. For example, to calculate the angle that produces a sine of
0.866, press .866 [ASIN] (arc sine).
The trigonometric functions (including the inverse functions) observe
the current angular mode for all calculations.
Example: Using the COS Function. Show that the cosine of (5/7)r
radians and the cosine of 128.57° are the same (to four decimal
places). Start by setting Radians mode (RAD turns on).
W(MovES) RANE ly: 24.9900
x: 8.6932
Calculate (5/7)r.
5 (ENTER) 7G) SG) E : 8.0832
2446
Calculate the cosine of (5/7)r.
cos
Now, switch to Degrees mode (RAD turns off).
WMooes) BREE
Calculate the cosine of 128.57°.
128.57 [Cos
When you're done, both results are in the display for you to compare.
Example: Calculating an Angle. The angle @ in the following trian-
gle can be determined by using the arc (inverse) trigonometric
functions.
5: Numeric Functions 81b
8 = arc sine (*/,) = arc cosine ('/.) = arc tangent (*/;)
Suppose a = 4 and c = 8. What is 6?
4 (ENTER) 8 iy: 0,623
x: G. 5008
@Gsin) ly: -0. 6235
i: 30. 6008
The angle @ is 30°.
The Conversion Functions
The first row of the CONVERT menu ({§[CONVERT]) contains six func-
tions for converting trigonometric units or coordinates.
(CONVERT (SDEG! Radians to degrees.
©SRABY Degrees to radians.
§34RH Hours-minutes-seconds to hours.
Hours to hours-minutes-seconds.
@REG!) Polar to rectangular.
3P0W) Rectangular to polar.
82 5: Numeric FunctionsConverting Between Degrees and Radians
The +DEG (to degrees) function converts a real number in the X-regis-
ter from radians into decimal degrees. Conversely, the RAD (to
radians) function converts a real number in the X-register from deci-
mal degrees into radians. (The current angular mode is ignored by
these two functions.)
For example, convert 0.5 radians to degrees.
-5 (B(CONVERT) : 30.0080
a be: 8826479
Convert 30° to radians.
30 §(CONVERT)
ly: 28.6479
x: 8.523
6!
25236
Using the Hours-Minutes-Seconds Format
The HP-42S has four functions for working with numbers expressed
in hours-minutes-seconds format. You may use this format for time
values (H.MMSSss) or angles expressed in degrees (D.MMSSss). For ex-
ample, the following numbers could represent the time 15:25:18.98 or
the angle 15°25’18.98":
15,.251898 15.4219
> SE
Hour minttes sabonds Hours or degrees in deci-
or (18.98) mal format (rounded to
degrees four decimal places)
Converting Between Formats. Values for time (in hours) or angles
(in degrees) can be converted between decimal-fraction form and
hours-minutes-seconds form using the one-number functions +HR (to
decimal hours) and +HMS (to hours-minutes-seconds).
For example, convert 1.25 hours to hours-minutes-seconds format.
1.25 (CONVERT) GRY : 9: 7e88
1
Executing would change 1.1500 (that is, 1:15:00 or 1°15’00”)
back to 1.2500.
5: Numeric Functions 83Arithmetic With Minutes and Seconds. To add and subtract time
(or angle) values in hours-minutes-seconds form, use the HMS+
(hours-minutes-seconds, add) and HMS— (hours-minutes-seconds, sub-
tract) functions.
For example, if a meeting started at 9:47 a.m. and adjourned at 1:02
p.m., how long was the meeting? Enter the two times in hours-min-
utes-seconds format. (Enter 1:02 p.m. as 13:02.)
13.02 [ENTER] 9.47 fy: 13.9288
pe Fede
Execute HMS— using the function catalog.
(B(CATALOG)
Use (¥] and (4) to find the HMS— function. (Remember, these keys
repeat if you hold them down.) When you find the function, execute it
by pressing the corresponding menu key.
onMS = 7 1.15008
he 311508
The meeting lasted 3 hours and 15 minutes.
>
To multiply or divide using an hours-minutes-seconds value, first con-
vert the number to decimal hours (§§(CONVERT) MII), then perform
the arithmetic. If you need the result expressed in hours-minutes-sec-
onds format, convert it back (§§[(CONVERT) SIE).
Coordinate Conversions (Polar, Rectangular)
The coordinate conversion functions are REC (to rectangular) and
+POL (to polar). The rectangular coordinates (x,y) and the polar co-
ordinates (r,0) are measured as shown in the illustration below. The
angle 0 is measured in the units set by the current angular mode. (The
current coordinate mode is ignored by these two functions.)
84 5: Numeric FunctionsBefore converting a set of coordinates, be sure the angular mode is set
to the proper units for # (page 80).
To convert rectangular to polar coordinates:
1. Key in the y-coordinate and press [ENTER].
2. Key in the x-coordinate.
3. Press (§[CONVERT | RMN. The polar coordinates (r and 6) replace
x and y in the X- and Y-registers.
To convert polar to rectangular coordinates:
1. Key in 6 and press (ENTER).
2. Key in the radius, r.
3. Press (CONVERT) (REM. The rectangular coordinates (x and y)
replace r and 6 in the X- and Y-registers.
5: Numeric Functions 85Altering Parts of Numbers
The second row of the CONVERT menu contains the following
functions:
W(CONVERT) (¥
Integer part.
Fractional part.
Round.
Absolute value.
Sign.
Modulo.
Integer Part (IP). The IP function removes the fractional part of a
real number. For example, the integer part of 14.2300 is 14.0000.
Fractional Part (FP). The FP function removes the integer part of a
real number. For example, the fractional part of 14.2300 is 0.2300.
Rounding Numbers (RND). The RND function rounds a real num-
ber to the number of digits specified by the current display format.
For example, to round a dollar value to the nearest penny, set the
display format to FIX 2 and then execute RND (M§(D!SP) Sammy 02
GELCONVERT) (¥) (aM).
Absolute Value (ABS). The ABS function replaces the number in
the X-register with its absolute value. If the X-register contains a com-
plex number, ABS returns r (the radius).
The Sign of a Number (SIGN). The SIGN function tests a real num-
ber in the X-register and returns:
| 1 if x is a number greater than or equal to zero.
= —1 if x is a number less than zero.
@ 0 if x is not a number.
If the X-register contains a complex number, SIGN returns the two-
dimensional unit vector (which is also a complex number).
86 5: Numeric Functions(
(
( ¢ ¢
C ¢
Modulo (MOD). The MOD function calculates the remainder of
y + x (where x and y are real numbers).
Probability
The PROB (probability) menu contains the following functions:
@lPros Combinations.
Permutations.
Factorial.
Gamma.
Random number (0 < x < 1).
Seed.
The Probability Functions
Combinations. The COMB (combinations) function calculates the
number of possible sets of y different items taken in quantities of x
items at a time. No item occurs more than once in a set, and different
orders of the same x items are not counted separately. The formula is
yt
Cue > gy — a
Permutations. The PERM (permutations) function calculates the
number of possible different arrangements of y different items taken in
quantities of x items at a time. No item occurs more than once in an
arrangement, and different orders of the same x items are counted
separately. The formula is
Pun = Gow
Factorials. The N! (factorial) function calculates the factorial of the
real number (integers only) in the X-register. For example, calculate 5!.
5: Numeric Functions 87PROB } SAE
568
x: 126. 6988
Gamma. The GAMMA function calculates T(x). Key in x and then
press (§(PROS | SRR
Generating a Random Number
To generate a random number: Press §§(PROS) MRAM. The RAN
function returns a number in the range 0 < x < 1.*
The calculator uses a seed to generate random numbers. Each random
number generated becomes the seed for the next random number.
Therefore, a sequence of random numbers can be repeated by starting
with the same seed.
To store a new seed:
1. Key in any real number.
2. Press (§(PAOS) SSH.
Whenever Continuous Memory is reset, the seed is reset to zero.
When the seed is equal to zero, the calculator generates a seed
internally.
* The random number generator in the HP-42S actually returns a number that is part of a
uniformly distributed pseudorandom number sequence. This sequence passes the spectral
test (D. Knuth, Seminumerical Algorithms, vol. 2, London: Addison Wesley, 1981).
88 5: Numeric FunctionsHyperbolic Functions
To use a hyperbolic function, key in x, then execute the function.
Hyperbolic sine of x.
Hyperbolic cosine of x.
Hyperbolic tangent of x.
Hyperbolic arc sine of x.
Hyperbolic arc cosine of x.
Hyperbolic arc tangent of x.
5: Numeric Functions 89Complex Numbers
As mentioned in chapter 3, complex numbers are one of the four
types of data used by the HP-42S. In this chapter you will learn:
= How to enter complex numbers.
= How complex numbers are stored and displayed.
® How to do arithmetic with complex numbers.
= How to convert the storage registers to hold complex numbers.
Entering Complex Numbers
There are two common notations for writing a complex number z:
@ Rectangular form: z = x + iy.
®@ Polar form: z = r AO.
90 6: Complex Numbers€ CC € ¢
( ¢ ¢
€€€ € ¢
Af
(
The following relationships exist and define how the two forms are
related.
x = rcos 6
y=rsin@
r= \PFF
-vt
There are two parts to a complex number: x and y, or r and 6. Each part
may be any real number. The angle 6 is expressed using the current angu-
lar mode (Degrees, Radians, or Grads).
To key in a complex number:
1. If necessary, set the correct coordinate and angular modes (using
the MODES menu).
2. Key in the left-hand part (x or r); press (ENTER).
3. Key in the the right-hand part (y or 6).
4. Press §§§[COMPLEX] to convert the two real numbers in the X- and
Y-registers to a complex number in the X-register. Each part is
displayed using the current display format.
For example, to key in the complex number 2 + i1, press 2 [ENTER
(B(comPcex].
The coordinate mode (Rectangular or Polar) determines how the cal-
culator interprets and displays complex numbers (as x + ty or r 48).
How (§(COMPLEX] Works:
™@ If the X- and Y-registers contain real numbers, executing
WCOMPLEX) combines them to form a complex number.
6: Complex Numbers 1@ If the X-register contains a complex number, executing @§[COMPLEX]
separates the number into two real numbers. The left-hand part
goes into the Y-register and the right-hand part stays in the X-
register.
x om»
With a printer you can:
Print intermediate and final results, including all types of data.
Keep a running record of your keystrokes and calculations.
.
.
™ List the names of programs and variables stored in the calculator.
® Print complete and partial program listings.
.
Print a copy of the display.
100 7: Printing(
CC CC ¢
C € ¢
€(€€CEECEE EE EC
¢
(
~
~
Common Printing Operations
The first two rows of the PRINT menu contains these print functions:
Print statistics.
Print program.
Print variable.
Print stack.
Print Alpha register.
Print X-register.
Print user (variables and programs).
List program lines.
Advance printer paper.
Print LCD (liquid crystal display).
Delay time between lines.
Here are a few common printing tasks:
To enable printing: Press (PRINT) (4) (EGNH (printing on). The
PRON function sets flags 21 (printer enable) and 55 (printer
existence).
The infrared printer port remains enabled until you disable it by
pressing §§(PRINT) (a (printing off). The PROFF function clears
flags 21 and 55.
To print the contents of the X-register: Press §(PRINT) [PRET -
To print the contents of a variable:
1. Press (PRINT) BPRUM.
2. Select the variable from the catalog, or type the variable name
using the ALPHA menu.
7: Printing 101For example, to print the contents of the storage registers (which are
stored as a matrix named REGS), press M§CPRINT) RMN GREE .
To print the contents of the Alpha register: Press §§(PRINT
UPRAL.
Printing Modes
How and when information is sent to the printer depends on the cur-
rent modes. The functions for controlling the printing modes are in
the third row of the PRINT menu:
BPaINT)
Printing on.
Printing off.
Manual mode.
Normal mode.
Trace mode.
To select a printing mode:
1. Press §§(PRINT) (a).
2. Press one of the following:
© HANH (Manual mode). Use this mode when you want the cal-
culator to print only when a print function is executed. The
VIEW and AVIEW functions can also generate printer output
in this mode. (This is the default mode.)
@ HORM (Normal mode). Use this mode when you want to print
a record of prompts and keystrokes.
@ |PRAGE! (Trace mode). Use this mode when you want to print a
record of prompts, keystrokes, and results. If a program is
running, each instruction is printed as it executes. This mode
is primarily intended for testing and debugging programs.
102 7: Printing€
Flags That Affect Printing
There are several flags that affect how and when information is
printed. For example, to cause all printing to be double-wide, set flag
12 ((§)(FLAGS) SEEM 12). To return to normal-width printing, clear
flag 12 (CFLAGS) HIM 12).
Double-wide printing.
Lowercase printing.
Printing mode.
Printer enable and printer existence. | 131 and 132
Printing Speed and Delay Time
Since the HP-42S is capable of sending information faster than it can
be printed by the HP 82240A Infrared Printer, the calculator uses a
delay time to avoid losing information. To optimize printing speed, set
the delay time slightly greater than the time it takes for your printer
to print a single line of information.
To set the printing delay time:
1. Key the delay time into the X-register (in seconds). The longest
delay time you can set is 1.9 seconds.
2. Press §§(PRINT) (7) BBE.
If you're operating the printer without an AC adapter, printing speed
will slow down as the batteries discharge. If you are using the longest
delay time (1.9 seconds) and your printer is still too slow, replace the
batteries or connect an AC adapter. Operating the printer with batter-
ies this low (without an AC adapter) will likely result in poor infrared
communication and may damage the printer.
7: Printing 103Low Calculator Batteries
To conserve battery power, the HP-42S will not transmit data to the
printer when the {=] annunciator is on. If low battery power occurs
after you've started printing, printing stops and the calculator dis-
plays Batt Too Low To Print. The calculator automatically
returns to Manual mode.
Calculator Functions That Print
If printing is enabled (after executing PRON), the VIEW and AVIEW
functions automatically generate printed output (in addition to per-
forming their normal functions).
For more information on how these functions and flags 21 and 55
affect program execution, refer to chapter 9, “Program Input and
Output.”
Printing Graphics in the Display
The PRLCD ( (PRINT) (¥) [BREGH) function copies the display to the
printer, pixel for pixel. The primary purpose for this function is to
print graphics that you create in the display using the PIXEL and
AGRAPH functions (page 135).
The “PLOT” program on page 160 creates a plot in the display and
then uses the PRLCD function to print it.
Printing Programs
To print an entire program:
1. Press §§(PRINT] MBREM (print program).
2. Select the program from the catalog, or type the program name
(global label) using the ALPHA menu.
104 7: Printing(
(
(€€ CECE E €
(
The PRP function prints the entire program, even if the global label
you specify is not the first line of the program.
If you do not specify any label ({§[PRINT] PREM (ENTER) (ENTER)), the
calculator prints the current program.
To print part of a program:
1. Position the program pointer to the line where you want to start
the listing (page 111).
2. Press §§(PRINT] (¥) Sets.
3. Key in the number of lines you want to print, nnnn. (If you enter
fewer than four digits, complete the instruction by pressing
(ENTER).)
The program listing begins with the current line and continues for
nnn lines or until an END instruction is encountered.
Character Sets
Some characters are not printed as you see them in the display. This
is because the character set used in the HP-42S does not directly
match the character set used in the HP 82240A Infrared Printer. Com-
pare the character table in appendix E of this manual with the
character set listed in the HP 82240A owner's manual.
7: Printing 105PIIPIIIAIIIIIIIVIINDIIAIIIIIIIIIVIIAIID DIDC(CECCEECECCEECEEEEECEECEECECECEECECEEECECE CE
Part 2
Page 108 8: Simple Programming
121 9: Program Input and Output
141 10: Programming Techniques
166 11: Using HP-41 ProgramsSimple Programming
Part 1 of this manual introduced you to several functions and opera-
tions that you can use manually (from the keyboard). In this chapter
you will learn how programs can be used to store and execute a se-
quence of functions. More specifically, you will learn:
@ How to key a program into memory.
= How to edit (change) a program.
@ How to execute (run) a program.
™ What happens when an error causes a program to stop.
® About the parts of a program.
™ How to clear a program from memory.
The programming information in this manual (chapters 8, 9, and 10)
should give you a good start at writing your own programs. If you're
interested in more advanced programming information and tech-
niques, refer to the HP-42S Programming Examples and Techniques
manual (part number 00042-90020).
An Introduction to Keystroke Programming
The sequence of steps a program uses to perform a calculation are the
same as the steps you would execute when solving the problem man-
ually. By programming your calculator you can repeat operations or
calculations without repeating the keystrokes every time.
For example, consider the formula for the area of a circle:
A=rr,
108 8: Simple ProgrammingCE COECCECE
€(€€€CECECEE E €
(
To calculate the area of a circle with a radius of 5, you would key in
the radius, square it, and then multiply by 7.
528)
The keystrokes (<7) (] &) can be stored as a program and then
executed any number of times for circles of different radii. Such a
program might look like this:
61 LBL "AREA"
2 Kt2
63 PI
O4 x
@5 END
This program assumes that the radius is in the X-register when the
program runs. To calculate an area, you would key in a radius and
then run the program. The result (the area of the circle) is left in the
X-register when the program ends.
The label (line 01) identifies the program so you can refer to it by
name. The END instruction (line 05) separates this program from the
next program in memory.
Example: Keying In and Running a Program. To key a program
into the calculator, press §§(GTO)()(C) to move to a new program space
(page 118), and then press {§J[PAGM) to select Program-entry mode.
(cro) 2) ©) Milprem Gort G-Byte Prom >
ai END.
Key in the program listed above.
PGM.FCN | S80 AREA (ENTER 9a € 8-Byute Pram >
. ae atetet "area °
The next three lines are the body of the program—that is, the part
that calculates the area of the circle. As you press the keys, the calcu-
lator records them and automatically numbers them as program steps.
8: Simple Programming 109ne
B2bxT2
a a2 xt2
JGSbPI
3} a3 PI
Ja4hx
The calculator has automatically provided an END statement for you,
so the program is complete. If you want to review the program before
exiting Program-entry mode, use [¥] and [4] to move up and down
through the lines of the program.
an
78.5398
Now you can use the program to calculate the area of any circle given
the radius, r. Key in a radius of 5 and run the program.
5 AREA” 7
The result is the same as when you solved the problem manually.
Find the area of a circle with a radius of 2.5.
2.5 (XEQ) SRE
Divide the two results.
+ iv: 78
x 4.
The area of a circle with a radius of 5 is 4 times greater than the area
of a circle with a radius of 2.5.
110 8: Simple Programming(
€€€ €CCCEECE € €
\
(
€¢
Program-Entry Mode
The §§(PRGM] key toggles the calculator in and out of Program-entry
mode. In Program-entry mode, functions and numbers you key in are
saved as program instructions.
The Program Pointer
While working the example above, you may have noticed the ® char-
acter in the display. This is the program pointer. It points to the current
program line. If the current program line is too long for the display,
press and hold the key to display the entire line.
Moving the Program Pointer
The following instructions are nonprogrammable, so you can execute
them in or out of Program-entry mode to move the program pointer.
To move the program Press:
pointer to:
The next program line. SST] (or [¥] if no menu is displayed)
The previous program
line.
BST} (or (4) if no menu is displayed)
current program.
A global label.
A new program space.
GTO} (-) (ENTER) /abe! (ENTER
(sto JG)
a
a
Line number nnnn of the — (GTO) E) nnnn
a
a
Inserting Program Lines
Instructions keyed into a program are inserted immediately after the
current program line and the pointer advances to the new line. There-
fore, to insert a program line between lines 04 and 05 of a program,
you would move the pointer to line 04 and then key in the
instruction.
8: Simple Programming a1Deleting Program Lines
To delete a program line, position the program pointer to the line you
want to delete, and then press (4). When you delete a line, the pro-
gram pointer moves to the previous line.
To delete several consecutive program lines, use the DEL (delete) func-
tion (page 120).
Executing Programs
In general, there are two ways to run programs:
®@ Normal execution. Program instructions continue to execute until an
instruction that stops program execution is encountered (such as
STOP, PROMPT, RTN, or END) or until you manually stop the
program by pressing or (EXIT).
@ Stepwise execution. Program instructions are executed one at a time
as you step through the program with the [SST] key. This method
of executing a program is especially useful when you are debugging
a program (testing for errors).
Remember, Program-entry mode must be off to run a program.
Normal Execution
To execute a program using the program catalog:
1. Press (XEQ) or §§(CATALOG) (IBGE.
2. Press the menu key corresponding to the program you want to
execute.
This method is used in the example on page 110.
To assign a program to the CUSTOM menu:
1. Press §§(ASSIGN) —RGHIN .
2. Press the menu key corresponding to the program you want to
assign.
112 8: Simple Programming€
(EEC CEECE EL € E
(
3. The CUSTOM menu has three rows; use [¥] or [4] to display the
row you want and then press the menu key where you want the
program assigned.
For example, assign the “AREA” program to the CUSTOM menu.
ASSIGN) BERGHE BRERE RSSTGN UARER® TO
Oe a A A
(dz) (the third menu key)
Now, each time you want to calculate the area of a circle, key in the
radius and then press [RIRERS .
5 “AREA
3.25 REE
EXIT,
Running a Program With [R/S
To run the current program beginning with the current program line,
press [R/S] (run/stop). If you hold the [R/S] key down, the calculator
displays the current program line (b); that is, the line to be executed
next. If you hold (R7S} down until NULL appears, the program does
not begin running when you release the key.
You can position the program pointer to the top of the current pro-
gram by executing the RTN function when Program-entry mode is
off. Therefore, to run the current program (beginning with the first
line), press (§(PGM.FCN] (RTH and then (R/S).
8: Simple Programming 113Stopping a Program
To stop a running program press [R/S] or [EXIT]. Execution halts after
the current instruction is completed. To resume execution, press [R/S
again.
Testing and Debugging a Program
lows you to execute any program one step at a time
key. This feature is particularly useful when you are
trying to find a bug (error) in a program or when you just want to see
how each instruction in a program works. (Note that if there is no
menu displayed, the [¥] and [a] keys can be used to execute the
(Sst) and §§[8s7) functions.)
While testing or debugging a program, you may want to use Trace
mode to print a running record of each program step as it is executed.
To select Trace mode, press §§(PRINT) :
To execute a program one step at a time:
1. Position the program pointer to the label or line number where
you want to start executing the program. If you skip this step,
execution will begin with the current program line.
2. Be sure Program-entry mode is off. If any data is needed at the
start of the program, enter it.
3. Press and hold to display the current program line. When
you release |, the instruction is immediately executed and
the program pointer advances.
If you hold the §§[SST] key down too long, NULL appears and
the program instruction is not executed when you release the
key.
When the program pointer reaches the end of the current program, it
wraps around to the first line.
You can move the program pointer up (backwards) through a pro-
gram with the §§[BST] key. The §§[BST) key:
™ Moves the program pointer without executing program instructions.
114 8: Simple Programming™@ Repeats when you hold the key down.
Error Stops
If an error occurs while a program is running, program execution
halts, and the appropriate error message is displayed. The error mes-
sage disappears when you press a key.
The program pointer stops at the line that generated the error. To
view the line, select Program-entry mode (§[PRGM}).
A running program will ignore an error if flag 24 (range ignore) or flag
25 (error ignore) is set. Refer to appendix C for more information on
these flags.
The Basic Parts of a Program
Program Lines and Program Memory
As you've already seen, when the HP-42S is in Program-entry mode,
keystrokes you enter are not immediately executed, but are stored in
program memory as instructions. Each instruction occupies a single
program line, which is automatically numbered.
Types of Program Lines. Program lines are divided into several cat-
egories. A program line may contain:
@ A program label (such as LBL “AREA").
@ A complete instruction (such as a simple numeric function, like +),
or an instruction that includes a parameter, like [STO] 14).
= A complete number (called a numeric constant).
@ An Alpha string of up to 15 characters (called an Alpha constant).
Memory Requirements. Program steps may vary in size from 1 to
16 bytes. At the top of each program (line 00) the calculator displays
the size of the current program in bytes.
8: Simple Programming 115If you run out of memory while trying to enter a program line, the
calculator displays Insufficient Memory. Refer to appendix B,
“Managing Calculator Memory.”
Program Labels
A label is an identifier placed at the beginning of a series of program
steps. Program labels may be used anywhere in a program. Generally,
a program starts with a global label. Within a program, individual
routines can be identified with local labels.
Global Labels. Global labels use Alpha characters and are distin-
guished by quotation marks around the label name.* For example, the
program at the beginning of this chapter has a global label:
@1 LBL "AREA"
Global labels may be one to seven characters long. The single-letter
names A through J and a through e are reserved for local Alpha la-
bels (which are displayed without quotation marks).
Global labels:
™ Can be accessed no matter where the program pointer is located.
™ Are listed in the program catalog (CATALOG) [EIGHIN).
@ Can be assigned to the CUSTOM menu.
@ Should be unique within calculator memory to avoid confusing one
program with another.
Local Labels. There are two types of local labels: numeric and Alpha.
™ Numeric labels are identified by two digits, LBL 9@ through
LBL 99. (LBL @@ through LBL 14 are called short form local la-
bels because they use less memory.)
™ Local Alpha labels use single Alpha characters, LBL A through
LBL J and LBL a through LBL e.
*To key in a global label that begins with a digit character, select an ALPHA submenu and
then type the digit. This forces the digit to become an Alpha character. For example, to key
in LBL ‘1", press J(PGMECN) 08 (GI 4 Without (BRIBE, the label is inter-
preted as LBL 01
116 8: Simple ProgrammingCC CCC E
€(€€CECEECECEEECECEL EEE €
(
Local labels are used to mark and provide access to various segments
of a program. The primary purpose for local labels is to facilitate pro-
gram branching. Refer to “Branching” in chapter 10.
Local labels can be:
™ Accessed only within the current program.
@ Duplicated in separate programs. That is, local labels do not need
to be unique within calculator memory, but they should be unique
within each program. (It is possible to use duplicate local labels
within a single program if you consider the search patterns used to
find local labels. Refer to page 148.)
The Body of a Program
The body of a program is where all the work is done. For example,
the body of the “AREA” program is:
@2 xXt2
@3 PI
a4 x
This program contains two functions (Xt2 and x) and a numeric con-
stant (PI).
Constants
Numeric Constants. A numeric constant is simply a number in a
program. When the line is executed the number is placed in the X-
register, lifting the stack just as if you keyed the number in from the
keyboard.
The PI function ({§[+]}) operates like a numeric constant. Thus, the
“AREA” program would return exactly the same result if line 03
looked like this:*
63 3.14159265359
* Although the program would run the same, keying in the 12-digit approximation for +
takes 14 bytes of program memory; the PI function requires only 1 byte.
8: Simple Programming 117Consecutive Numeric Constants. Because numeric constants in
programs are on different program lines, [ENTER] is not needed to sep-
arate them. Consider these two programs:
@1 12 @1 12
@2 ENTER @2 17
03 17 @3 x
o4 x
Both programs produce the same result (12 x 17), however the one
on the right is one line shorter and saves one byte of program mem-
ory. To key in the program lines on the right, press 12 [ENTER] [4] 17
x).
Program ENDs
Programs are separated from one another with END instructions. The
last program in memory uses the permanent END, which appears in
the display as .END..
After the first program in memory, you should insert an END between
subsequent programs so they will be considered as separate programs,
and not just labeled routines within the same program. There are two
ways to enter an END at the end of a program:
@ Press §(GTO}() (J. This procedure automatically inserts an END
after the last program in memory and positions the program
pointer to the new program space at the bottom of program mem-
ory. This space contains the null program:
96 ¢ B-Byte Pram >
@1 .END.
™ Or, manually execute the END function (press (xEQ] [ENTER] END
ENTER] or use the function catalog).
Because END instructions separate programs, deleting an END causes
the two programs to be joined as one program. You cannot delete the
permanent .END..
118
imple Programming(CE ECC E ¢
(
(
Clearing Programs
To clear an entire program from memory:
1. Press §§(CLEAR) GER.
2. Specify the program you want to clear using one of the
following:
™@ Press the menu key corresponding to a global label in the
program.
™ Use the ALPHA menu to type a global label ((ENTER
CENTER).
@ Or, press [ENTER] [ENTER] to clear the current program.
8: Simple Programming
label
119To clear a portion of a program:
1. Press §§J[PRGM) to select Program-entry mode (if the calculator is
not already in Program-entry mode).
2. Position the program pointer to the first line in the range of lines
you want to delete.
3. Press §§(CLEAR] (¥) MBE (delete)
4. Key in the number of lines you want to delete.
For example, to delete lines 14 through 22 of the current program,
you would press: §§J(PRGM] (to select Program-entry mode), §§(GTO)C
14 [ENTER] (to position the program pointer to line 14), § RJ (¥)
DEW 9 [ENTER] (to delete 9 program lines).
The DEL function deletes program lines only if the calculator is in
Program-entry mode.
120 8: Simple Programming€(€ECECECEEECECEEECECECEEECEEC EEE
Program Input and Output
An interactive program has two general characteristics:
@ Input. The program prompts you to key in information or make a
selection.
™ Output. The program presents results in a meaningful format using
the display or a printer.
This chapter covers functions and techniques for making programs
easier to use. You'll learn about:
= Prompting for values and using variable menus.
™ Displaying labeled output and messages.
@ Printing during program execution.
® Working with Alpha data.
® Displaying graphics.
Using the INPUT Function
Using the INPUT function is one of the simplest ways for a program
to prompt for data to be stored into a variable or register. When an
INPUT instruction is executed:
™@ The current value of the variable or register is recalled into the X-
register. If you use a new variable name, the INPUT function
automatically creates the variable and assigns an initial value of
zero.
@ The normal label for the X-register (x: ) is replaced with the name
of the variable or register being input and a question mark.
9: Program Input and Output 121@ Program execution halts, allowing you to key in or calculate a
value.
When you press (R/S
stored into the variable or register and program execution continues.
Pressing [EXIT
, the value in the X-register is automatically
(if there is no menu displayed) cancels the INPUT
function without storing any data. If you then press (R7S], the INPUT
is resumed with the original value.
Example: Using INPUT. The formula for the surface area of a box is
Area = 2 (length x height) + (length x width) + (height x width)).
The following program uses INPUT to prompt for the values of L, H,
and W and then calculates the surface area.
@1
e2
63
e4
es
LBL "“SAREAR"
INPUT "L"
INPUT "H"
INPUT "W"
RCLx "L"
Inputs each of the three
variables.
Calculates length x width. The
value of W is already in the X-
register because it was the last
value input.
Calculates height x width
Calculates length x height
Calculates sum of the products,
multiplies by 2, and leaves the
result in the X-register.
9: Program Input and OutputCCE ECECECEEEE EEE
(€€ CEE
\
(
Key the program into your calculator.
@(cto) FD Prem) gor< 6 Bute Prom +
W(PamFcn) M(PSMFCN)
SAREA (ENTER
Wlie@ (ENTER) L (ENTER
(eum (ENTER) H (ENTER @Sh INPUT "H"
IS Td TT CT
(ee (ENTER) W (ENTER) (EXIT ut ff
RCL] (x) (ENTER) L (ENTER T "W"
x ube
gS RCLX "L"
JGERLASTX
RCL) (x) (ENTER) H (ENTER 96 LAST:
BopReEX “H"
RCL] (ENTER) H (ENTER) i? RCLX "H"
eapBet "H"
RCL) (x) (ENTER) L (ENTER gs RCL "H"
@9PRCLX "L"
+ Bo RCLX "Le
16b+
+ 16+
11b+
2 12.2
13h
EXIT
9: Program Input and Output 123Run the program to calculate the surface area of a box that is 4 x 3
x 15
meters.
XEQ) (SARER!
vy: 6.8008
L?78. 8068
The program is prompting for a value of L. Key in the length (4) and
press [R/S].
4 (RS
Key in
3 (R/S
Key in the width (1.5) and press (R/S).
the height (3) and press
1.5
R/S.
The surface area is 45 square meters.
R/S}.
fy: 4.0008
IH?76. 8868
What is the surface area of a box that is twice as long? Run the pro-
gram again. This time multiply the length by 2 and leave the other
values
XEQ
as they are.
x
(Rvs
R/S
R/S
The surface area is 81 square meters.
124
9: Program Input and Output
mz
St
pp
en
oo
|
S|
*4) [Ss $
53] |:
re
o5)
3) oo
89] |S] [os] |
=<
)
Bee
ue |eo| |o
oo)
e009]
me
oJ
|
¥s
@
SI
S( ¢
CC ECEE EC
(
¢
Using a Variable Menu
Using a variable menu may be the most efficient way for a program to
input values for several variables. The VARMENU (variable menu)
function creates a menu containing variable names. When the pro-
gram stops, the menu is displayed allowing you to store, recall, and
view variables.
The VARMENU function requires a global program label as a param-
eter. When a program executes VARMENU, the calculator searches
for the specified program label. It then builds the variable menu using
the MVAR (menu variable) instructions immediately following the
specified label. (The calculator ignores MVAR instructions except
when they are being read by the VARMENU function.*)
To store a value into a menu variable:
1. Key in or calculate the value.
2. Press the corresponding menu key.
To recall the value of a menu variable:
1. Press (RCL).
2. Press the corresponding menu key.
To view a menu variable without recalling it:
1. Press §§ (shift).
2. Press and hold the corresponding menu key. The message disap-
pears when you release the key.
*The Solver and Integration applications also use variable menus defined with MVAR
instructions.
9: Program Input and Output 125To continue program execution:
@ Press a menu key.
@ Or, press (R/S).
If you continue by pressing a menu key, the name of the correspond-
ing variable is stored into the Alpha register. Your program can use
this information to determine which key was pressed. If you continue
by pressing [R/S], the Alpha register is not altered.
To exit from a variable menu:
@ Press (EXIT).
™ Or, select an application menu ((§(SOLVER), HW)
@(sta7), or M(EAse)).
Example: Using a Variable Menu. In the previous program, the
INPUT function was used to prompt for three variables. By replacing
lines 02, 03, and 04 with the following seven program lines, you can
add a variable menu to the program.
BWwaTAx),
@2 MVAR "L" Declares the menu variables fol-
83 MVAR "H" lowing the global label.
94 MVAR "HW"
@5 VARMENU “SAREA" Creates the variable menu and
@6 STOP stops the program. When the
67 EXITALL program is restarted, the variable
menu is exited.
@8 RCL " Since the variables in a variable
menu can be entered in any or-
der, there is no gaurantee that W
will be in the X-register (as there
was in the first program).
Edit the “SAREA” program. First delete lines 02, 03, and 04.
@lPrcm) (CTO) C) 4 (ENTER) as INPUT
24> INPUT
Has @1eLBL "SAREA"
2 RCLx "L"
126 9: Program Input and Output¢
€€€ € € ¢
€(€CECEECECE € E
i
€
Now insert the new program lines.
PGM.FCN )
a
Grom Fcn) BI
ee]
MVAR, OH
XEQ) SARER
Y) ... CY) EXT
RCL] RE
EXIT
UMVARE
B2bNVAR "L"
TT A ed TT TS CL
BSPMVAR "H"
CT TA CT CST
B4bNVAR "WI"
ia
(OShYVARMENU "SAREA
E
IS. YARMENU "SAREA"
|@6hSTOP
IBERSTOP
CL
Use the arrow keys to find the EXITALL function in the catalog.
G6 STOP
\@?bEXI TALL,
je? EXITALL
e2shRCL "Wl"
Now run the new version of the program.
The variable menu is displayed, ready to use. Calculate the surface
area of a box that is 5.5 x 2 x 3.75 cm.
9: Program Input and Output 1273.75
R/S.
EXIT,
vy: 3.7508
x: 783.2588
The surface area is 78.25 cm?.
Displaying Labeled Results (VIEW)
To display the contents of a variable or register use the VIEW func-
tion. VIEW creates a message that includes the variable or register
name, an equal sign, and the data stored there. (Also refer to “Printing
With VIEW and AVIEW” on page 132.)
For example, add these two lines to the end of the “SAREA” program.
18 STO "SAREA"
19 VIEW "SARER"
Line 18 stores the result into a variable named SAREA. Line 19 dis-
plays the contents of SAREA.
0 (Sto) (ENTER) SAREA (ENTER iy: 73.2500
x: 8. 868
W®lPRcM) (GTO) () 17 (ENTER 16 2
17bx
STO} SARE
WPcuFCN) VTEW! SARER
128
18bSTO "SAREA"
18 STO "SAREA"
19PVIEW "SAREA"
9: Program Input and Output
(
(¢
(
€€€ € € € ¢
(
EXIT,
: 78,2508
8.0000
Now, run the program again using dimensions of 2 x 3 x 4 m.
TES) (ARE
2 SE 3 RA 4 Me [R/s SAREA=52. 0000
he: 52. 0808
This time the answer is labeled for you. This technique is particularly
useful when a program has several results.
Displaying Messages (AVIEW and PROMPT)
Messages are useful in programs to display descriptive prompts, out-
put, and error conditions. For a program to display a message, it
must:
1. Create the message in the Alpha register with an Alpha string.
2. Display the contents of the Alpha register.
To create a two line display, insert the line feed character (§pwaGy (Y)
{@08ME) into the Alpha register as part of your message. When you
execute AVIEW or PROMPT, characters following the line feed char-
acter are displayed on the second line of the display.
You can use more than one line feed character to produce multiline
messages on the printer. However, since the calculator has a two-line
display, anything following the second line feed character (within the
same message) cannot be displayed.
The AVIEW Function. The AVIEW function displays the contents of
the Alpha register. Depending on the status of flags 21 and 55,
AVIEW may halt program execution or produce printer output. Refer
to “Printing With VIEW and AVIEW’ on page 132.
The PROMPT Function. The PROMPT function displays the con-
tents of the Alpha register just as AVIEW does. However, PROMPT
always halts program execution and only generates printer output in
Normal and Trace printing modes.
9: Program Input and Output 129Entering Alpha Strings Into Programs
An Alpha string entered as a program line—called an Alpha con-
stant—is placed into the Alpha register when that line is executed. For
a normal Alpha constant, like the one that follows, the Alpha string
replaces the previous contents of the Alpha register.
@1 "This is an"
If the append symbol precedes an Alpha string, the calculator appends
the string to the current contents of the Alpha register.*
@2_F" Alpha String"
Append symbol.
After executing these two program lines, the Alpha register contains:
This is an Alpha String
The “SMILE” program on page 139 uses program lines like this to cre-
ate a special string in the Alpha register.
To key an Alpha string into a program:
1. Press §§[ALPHA) to display the ALPHA menu.
2. Optional: press [ENTER] to insert the append symbol (+).
3. Type the string.
4. Press [ENTER] or §§[ALPHA] to complete the string.
An Alpha string in a program may be up to 15 characters long. (The
append symbol counts as a character.)
If the Alpha register fills up (44 characters), appending more charac-
ters pushes the left-most (oldest) characters out of the Alpha register.
* Note that some printers may not be able to print the append character.
130 9: Program Input and OutputThis program displays three consecutive messages:
@1 “Hello there,"
@2 AVIEW
@3 PSE
64 "this program"
@S5 AVIEW
@6 PSE
@7 "has 3 messages."
68 AVIEW
@9 END
Without the PSE instructions (lines 03 and 06) the program would run
too fast to see the first two messages. A PSE is not needed after the
last AVIEW because the viewed information remains in the display
after the program stops. Pressing a key during a PSE causes program
execution to halt. Press [R/S] to resume program execution.
Printing During Program Execution
Printing is another important form of program output. For a complete -
description of print functions and modes, read chapter 7, “Printing.”
Using Print Functions in Programs
When a print function (such as PRX, PRA, or PRV) is encountered in
a running program, the calculator tests flags 21 and 55. In general,
flag 21 (printer enabled) determines if printing is desired and flag 55
(printer existence) determines if printing is possible.
Flag 21 Flag 55 Result of Print Function
Clear Set or clear | The print function is ignored and program execu-
tion continues with the next line.
Set Clear Program execution halts and displays
Printing Is Disabled
Set Set The print function is executed and the program
continues.
9: Program Input and Output 131Printing With VIEW and AVIEW
Like print functions, VIEW and AVIEW also test flags 21 and 55. In
addition to performing their normal display functions, VIEW and
AVIEW produce printed output if flags 21 and 55 are set.
To record results, set flag 21. If a program uses VIEW or AVIEW
to display important results, set flag 21. Then if printing is enabled
(flag 55 set), the information is printed.
If printing is disabled (flag 55 clear), the program stops so you can
write down the displayed information. Press (R/S) to continue.
To display, but not record messages, clear flag 21. If flag 21 is
clear, flag 55 is ignored by VIEW and AVIEW. The information is dis-
played and program execution continues.
Working With Alpha Data
This section describes the functions for manipulating data in the Al-
pha register. All of the techniques presented here can be executed
manually; however, they are primarily meant for programming.
Moving Data Into and Out of the Alpha Register
In addition to keying data directly into the Alpha register or entering
strings in programs, there are several ways to move data into and out
of the Alpha register.
Storing Alpha Data. The ASTO (Alpha store) function copies the
first six characters in the Alpha register into the specified variable or
register. To execute the ASTO function:
1. If Alpha mode is not on, press §§J[ALPHA].
2. Press (ASTO). (The (STO) key executes ASTO when Alpha mode is
on.)
132 9: Program Input and Output¢
¢
¢
(€CECEE EE €
\
(€C € ¢€ € €
3. Specify where you want the string to be stored:
™@ In a storage register. Key in the register number.
@ Ina variable. Press a menu key to select the variable or use the
ALPHA menu to type the name.
@ In a stack register. Press ©) followed by S520), ESTRRY,
SSTiyi, ISTH], or ESTE.
For example, to copy the first six characters of the Alpha regis-
ter into the X-register, press §§[ALPHA] (ASTO) [) SSaRE.
Recalling Data Into the Alpha Register. The ARCL (Alpha recall)
function recalls data into the Alpha register, appending it to the cur-
rent contents. To execute the ARCL function:
1. If Alpha mode is not on, press [ALPHA].
2. Press [ARCL]. (The [RCL] key executes ARCL when Alpha mode is
on.)
3. Specify the storage register, variable, or stack register you want
to recall. (Refer to step 3 above.)
If you recall a number into the Alpha register, it is converted to Alpha
characters and formatted using the current display format. Recalling a
matrix into the Alpha register recalls its descriptor (such as
C 2x3 Matrix J).
When the Alpha register fills up, characters at the left end of the reg-
ister (the “oldest” characters) are lost to make room for the new data.
To recall an integer into the Alpha register:
1. Place the number in the X-register.
2. Press §§(PGMECN) (¥) (¥) SREB (Alpha append integer part). The
AIP function appends the integer part of the number in the X-
register to the current contents of the Alpha register.
You can produce a similar result by using FIX 0 display format, clear-
ing flag 29 (to remove the decimal point), and recalling a number
using ARCL. A number recalled this way, however, may be rounded
if the fractional part of the number is greater than or equal to 0.5.
9: Program Input and Output 133To translate a number into a character:
1. Key in the character code (the allowed range is 0 through 255).
Appendix E lists all of the display characters and their character
codes.
2. Press §§(PGM.FCN)(¥) (¥) SREBRB (X to Alpha).
If the X-register contains an Alpha string, the entire string is ap-
pended to the Alpha register.
If the X-register contains a matrix, the XTOA function uses each ele-
ment in the matrix as a character code or Alpha string. XTOA begins
with the first element (1:1) and continues rowwise (to the right) until
it reaches the end of the matrix. If the Alpha register fills up, only the
~ last 44 characters to be appended will remain.
The XTOA function is especially useful for building a graphics string
in the Alpha register. Refer to the program on page 139.
To translate a character into its character code: Execute the
ATOX (Alpha to X) function. ATOX converts the left-most character in
the Alpha register into its character code (0 through 255) and returns
the number to the X-register. The character is deleted from the Alpha
register, shifting the rest of the string left one position. If the Alpha
register is empty, ATOX returns zero.
For example, if the Alpha register contains Janet, executing ATOX
deletes the J and returns its character code (74) to the X-register.
Searching the Alpha Register
To search the Alpha register for a character or string, use the POSA
(position in Alpha) function. POSA searches the Alpha register for the
target in the X-register. If a match is found, POSA returns the position
number where the target was found (counting the left-most character
. as position 0). If a match is not found, POSA returns —1.
" The target may be a character code or an Alpha string. POSA saves a
copy of the target in the LAST X register.
134 9: Program Input and Output¢
(
( ¢
\
(
CCE €C€€
Manipulating Alpha Strings
Once a string is in the Alpha register, there are several functions you
can use to manipulate the data.
Finding the Length of an Alpha String. The ALENG (Alpha length)
function returns to the X-register the number of characters in the Al-
pha register.
Shifting the Alpha Register. The ASHF (Alpha shift) function de-
letes the six left-most characters in the Alpha register. You may want
to shift characters out of the Alpha register after using the ASTO
function.
Rotating the Alpha Register. The AROT (Alpha rotate) function ro-
tates the contents of the Alpha register by n characters (n is specified
in the X-register). If n is positive, the rotation is to the left. If n is
negative, the rotation is to the right.
Graphics
Using the functions PIXEL and AGRAPH (Alpha graphics), you can
create graphics in the display of the HP-42S. The “DPLOT” and
“PLOT” programs in the next chapter use the PIXEL function to pro-
duce graphs of functions (pages 156 and 160).
Turning On a Pixel in the Display
The PIXEL function turns on a pixel (one dot in the display) using the
numbers in the X- and Y-registers. The x-value specifies the column
(numbered from left to right; 1 through 131), and the y-value specifies
the row (numbered from top to bottom; 1 through 16).
1 131
a
16—>|
9: Program Input and Output 135For a program to turn on a pixel in the display, it should:
1. Put the row number in the Y-register and the column number in
the X-register.
2. Execute the PIXEL function (§§(PGMFCN) CY) C¥) (ESE).
Executing PIXEL turns on the specified pixel and sets the message
flags (flags 50 and 51). This allows subsequent PIXEL and AGRAPH
instructions to add to the existing display.
To start with a clear display, execute CLLCD (clear liquid crystal dis-
play) before turning pixels on.
Drawing Lines in the Display
The PIXEL function can also be used to draw vertical and horizontal
lines across the display. To draw a vertical line, use a negative x-value
(—1 through — 131). To draw a horizontal line, use a negative y-value
(—1 through —16). If both numbers are negative, then PIXEL draws
two lines—one vertical and one horizontal.
The plotting programs at the end of the next chapter use this feature
of PIXEL to draw an x-axis.
Building a Graphics Image Using the Alpha Register
To create a graphics image in the display, a program should:
1. Create a string of characters in the Alpha register with each
character specifying a column of eight pixels.
2. Specify where in the display the upper-left corner of the image
should begin. Put that pixel-row number in the Y-register and
the pixel-column number in the X-register.
3. Execute the AGRAPH function ({g(PawFcn) (¥) (7) BRRSRER).
136 9: Program Input and Output(
€€€ ¢€ €
CO € ¢
The status of flags 34 and 35 determine how the graphics image is
displayed:
Flag 34 | Flag 35 How the AGRAPH Image is Displayed
Clear* Clear* The image is merged with the existing display (logi-
cal OR).
The image overwrites all pixels in that portion of
the display.
Clear Set
Set
Set All pixels are reversed (logical XOR).
* Default setting
Creating an Alpha String for AGRAPH. The AGRAPH function
uses the character code of each character in the Alpha register as an
eight-bit pattern for a column of pixels.
Duplicate “on” pixels get turned “off.”
Each pixel in a column has a special value. Adding the values for all
the pixels you want to display in a single column gives you the char-
acter code needed to produce that column.
Value Dots to Print Print Entry
1 s——>_— 1
2 a———> 2
4 o
8 o
16 o
32 a———> ‘2
64 s——_>_ 4
128 o —
99 <€—— Column Print Number
To append the character to the Alpha register, key in the character
code and then execute the XTOA function. You can type the character
directly into the Alpha register if it is a typeable character. (Refer to
the character table in appendix E.) For example, the character code 99
(calculated above) is the code for “c’.
9: Program Input and Output 137Example: Using Binary Mode to Calculate a Column Value. You
can use the built-in Base application* to convert a column pattern into
a character code. For example, select the Base application and Binary
mode.
x: 110166
La... [HEM] pects]
Key in the column pattern above as a binary number. Start at the
bottom, keying in a 0 for “off” pixels and a 1 for “on” pixels. (You can
omit the leading zero if you want.)
01100011
Display this number in Decimal mode.
Hen] bee [CTH] EINM [LOGIC]
You don’t have to use Decimal mode to use this number. While still in
Binary mode, you could append the character to the Alpha register
using the XTOA function.
Example: Displaying a Happy Face. The program below creates
this happy face in the display.
128 D000000n00
Column Print Numbers —y> 16 eh oa a7 ®
Use the character table in appendix E to look up these character
codes. If the table does not have keystrokes for a particular character
(in this case character number 27), then append it to the Alpha regis-
ter with the XTOA funciton. Refer to lines 03, 04, and 06 in the
following, program.
* Refer to chapter 16 for more information on the Base application,
138 9: Program Input and Output(€€€CEEE EC E (
(
( € ¢
C€€C CEE E€ €
(
@1 LBL "SMILE"
@2 "e" Character number 16.
@3 27 Character number 27.
@4 XTOA
a5 F"#eeeH" Character numbers 35, 64, 64,
64, and 35.
@6 XTOA Character 27 (X-register still con-
tains 27).
a7 Rte" Character number 16.
a8 5 Specifies the location of the im-
@9 62 age: row 5, column 62. (To key in
the two numbers press 5 [ENTER
‘#) 62.)
16 CLLCD Displays the image and stops.
11 AGRAPH
12 END
Key in the “SMILE” program. (If you are still in the Base application
from the previous example, press [EXIT].)
Bia) 0) Mlrreu BC G-Byte Prom >
«END.
G(PGMFCN | SBE SMILE (ENTER {_9-Byte Prom >
bLEL "SMILE"
T
(BLALPHA) ~ (ENTER]* BL "SMILE"
pen
27
oS)
o| |-o|
SS)
fet
OS)
Po} | rom}
So] [55]
BO] [cor
vy iiv
><] |Po =|
SN] [Nt
oy}
D
BPSwECN)() (7) mene
* After displaying the ALPHA menu ( [J(ALPHA), the keystrokes to type ¢ are: (7) [E05
Bee
9: Program Input and Output 139G(ALPHA] [ENTER] #@@@# *
@lPcmFcn) (¥) (7) SaGRAS
b'#GGet
aS Ss CS GT TE
WilPcmFcn) (y) Cy) Seon eS b"#eee#"
BERXTOR
QB(ALPHA) (ENTER) ~ (ENTER a6 xTOR
Behn e"
5 [ENTER] (@ e35
j@3_. END.
62 es 5
ash62_
CLEAR) (¥) ao! Bo 62
a 1@PCLLCD
16 CLLCD
11PAGRAPH
Now exit from Program-entry mode and run the program.
EXIT] (XE) SHEE! Tr
:
* After displaying the ALPHA menu and the append character ({J[ALPHA] (ENTER), the key-
strokes to type #@@@# are: (¥) (HIGGS EWI CHSC! (7) GRMN HNaSOy (v) HRS
verse (7) [pies parse: wes.
140 9: Program Input and Output€€ € € C
\
i
CC €€ € ¢
€
(
¢
(
10
Programming Techniques
This chapter covers functions and techniques for writing more sophis-
ticated programs. You'll learn how to use:
™ GTO (go to) and XEQ (execute) instructions to cause program
branching to execute subroutines and other programs.
™ The programmable menu to create menu-driven programs.
™ Conditional tests and counters to create program loops (routines
that repeat themselves).
™ Tests and comparisons to make decisions and cause program
branching.
Branching
Branching occurs whenever the program pointer moves to a line other
than the “next” line—that is, whenever program instructions are not
executed sequentially. The two primary functions for branching are
GTO and XEQ.
Often flag tests and comparisons are followed by branching instruc-
tions that are executed according to the result of the test or
comparison.
Branching to a Label (GTO)
Labels can be considered destinations for branching instructions. As
explained in chapter 8, global labels can be accessed from anywhere
in memory and local labels can be accessed only from within their
own program.
10: Programming Techniques 141There are three programmable forms of GTO instructions:
® GTO nn for branching to a local numeric label (where nn is the la-
bel number).
™ GTO J/abel for branching to a local Alpha label (where /abel is a sin-
gle letter A through J or a through e).
@ GTO "label" for branching to a global label (where /abel is the Al-
pha label).
Here are a few examples:
Example
Instruction: Description (Keys):
GTO 63 Branches to LBL @3 (@§[GTO) 03).
GTO A Branches to LBL A (@§(GTO) (ENTER
A (ENTER).
GTO "AREA" Branches to LBL "AREA" (@§(GTO) QARERE).
Executing GTO in a Program. In a running program, a GTO in-
struction causes program execution to branch to the specified label
and continue running at that line.
Executing GTO From the Keyboard. Executing a GTO instruction
from the keyboard moves the program pointer to the corresponding
label. No program lines are executed.
Indirect Addressing With GTO. The following examples show how
indirect addressing can be used with GTO instructions. That is, the
label to be branched to is specified in a variable or register.
142 10: Programming Techniques¢
(
C ¢
{ (
Example
Instruction: Description (Keys):
GTO IND 12 Branches to the label specified in storage regis-
ter Ry ((§(G1O) CF) MENG 12). For example, if
Rj contains the string “AREA”, then program
execution branches to LBL "AREA".
GTO IND "ABC" Branches to the label specified in the variable
ABC ( (GTO )-) MAR IEEE ). For example, if
ABC contains the number 17, then program
execution branches to LBL 17.
GTO IND ST Xx Branches to the label specified in the X-register
( (610) C) BRAG (-) BSMERE). For example, if
the X-register contains the number 96, then
program execution branches to LBL 96.
Calling Subroutines (XEQ and RTN)
The GTO function, described above, is used to make a simple pro-
gram branch. XEQ is used in much the same way with one important
difference: after an XEQ instruction has transferred execution to the
specified label, the next RTN (return) or END instruction causes the
program to branch back to the instruction that immediately follows
the XEQ instruction.
XEQ instructions are subroutine calls. A subroutine call is not com-
plete until a RTN or END has been executed to return program
execution to the line following the XEQ instruction.
XEQ is also used to run programs from the keyboard ([XEQ)).
Example: GTO versus XEQ. Consider the following two programs.
If you execute the first program ([{XEQ) HRRGHE), TONE @ never exe-
cutes because the GTO instruction branches to the second program.
Program execution halts when the END is reached in the second
program.
10: Programming Techniques 143@1 LBL "PRGL" @1 LBL "PRG2"
@2 GTO "PRG2" @2 TONE 9
@3 TONE @ @3 END
@4 END
However, if you replace line 02 of the first program with an XEQ in-
struction (KEQ “PRG2"), both TONEs will sound. When the END is
encountered in the second program, execution returns to the line im-
mediately following the XEQ. Program execution halts at the END in
the first program.
@1 LBL “PRG1" @1 LBL "PRG2"
@2 XEQ "PRG2" @2 TONE 9
@3 TONE @ @3 END
@4 END
Subroutine Return Locations. When an XEQ instruction calls a
subroutine, the HP-42S remembers the location of that XEQ instruc-
tion so that execution can return there when the subroutine is
completed.
For example, this illustration shows how the calculator nests subrou-
tines by remembering return locations. The HP-42S can remember up
to eight pending return locations.
Main program
(top level)
LBL A
REQ B
SIN
RTN
End of
program
144 10: Programming TechniquesC ¢
( (CECECEE € fC
(€€ € € ¢
(
(
Loss of Subroutine Returns. Pending return locations are lost un-
der the following conditions:
@ If there are already eight pending return locations when another
subroutine or program is called with an XEQ, the first (oldest) re-
turn location is lost.* In this case, program execution never returns
to the first XEQ that called a subroutine. Instead, execution halts
when the first subroutine is finally completed because there are no
further return locations.
@ All pending return locations are lost when you execute any pro-
gram from the keyboard or perform any other operation (while
program execution is halted) that alters the program pointer. Press-
ing M(SST) or (R/S) does not cause return locations to be lost.
The Programmable Menu
The HP-42S has a programmable menu which is used to cause pro-
gram branching. The MENU function selects the programmable
menu. The menu is displayed when the program stops. You can de-
fine each key in the menu so that when the key is pressed, a
particular GTO or XEQ instruction executes. You can even define [4],
(¥), and (exit).
To define a menu key:
1. Enter a string into the Alpha register. This is the text that ap-
pears in the menu label above the key. (The Alpha register is not
used when defining (4), (¥), or (EXIT).)
2. Execute KEYG (on key, go to) or KEYX (on key, execute). (These
functions are in the last row of the PGM.FCN menu; press
WlPamFcn) (4).)
3. Specify which key you want to define:
® Press (+), (17x), (), (L0G), (ON), (xEQ), (4), [¥), or (Exit).
™ Or, key in the key number, 1 through 9.
* The Solver and Integration applications also create return locations. If the calculator loses
one of these returns, program execution stops and an error message is displayed.
10: Programming Techniques 1454. Specify a program label using one of these methods:
® Select an existing global label by pressing the corresponding
menu key.
@ Use the ALPHA menu to type an Alpha label (local or global):
ENTER] Jabel [ENTER].
@ Key in a two-digit numeric label.
Repeat this procedure for each menu key you want to define. Defin-
ing a key replaces any previous definition that may exist for that key.
To display the programmable menu: Execute the MENU function
(press §§(PGM.FCN) (a) RRRIE).
To clear all programmable menu key definitions: Execute the
CLMENU (clear menu) function (press [CLEAR] (¥) SRRIRE).
Example. The program segment listed below shows how the pro-
grammable menu can be used to emulate this menu:
XEQ
va
146 10: Programming TechniquesLBL "YEAR"
LBL A
"JAN"
KEY 1 XE@
“FEB"
KEY 2 XEQ
“MAR”
KEY 3 XEQ
"APR"
KEY 4 XEQ
"MAY"
KEY 5 XEQ
"JUN"
KEY 6 XEQ
KEY 7 GTO
KEY 8 GTO
KEY 9 GTO
MENU
LBL 20
STOP
GTO 20
LBL B
"JUL"
KEY 1 XEQ
"AUG"
KEY 2 XEQ
"SEP"
KEY 3 XEQ
"oct"
KEY 4 XEQ
"Noy"
KEY 5 XEQ
"DEC"
KEY 6 XEQ
a1
62
a3
aq
es
o6
99
or
os
eo
18
11
12
Defines the first row of the “YEAR” menu. A
different subroutine is executed for each
month. The routines for the first six months
are labeled with local labels 01 through 06.
Defines the [4], (¥], and keys. The (a)
and (¥] keys are defined to go to the same
program label (LBL B) because this is a two-
row menu; either key should display the
second row. The [EXIT] key is defined to cause
a branch to a routine that exits the menu.
The programmable menu is selected and the
program stops. Because of this little loop,
pressing (R7S] keeps the program at line 20.
Defines the menu keys for the second row of
the “YEAR” menu.
10: Programming Techniques 14735 KEY ? GTO A
36 KEY 8 GTO A
37 LBL 21
38 STOP
39 GTO 21
48 LBL 99
41 CLMENU
42 EXITALL
43 RTN
44 LBL 61
Defines the [a] and [¥] to return to the first
row of the menu. The [EXIT] key does not
need to be define again. The definition made
at line 17 is still in effect.
Stops the program. The programmable menu
is still selected (line 18).
The menu definitions are cleared and the
menu is exited. If this program was called as
a subroutine from another program, execution
returns to that program.
The rest of the program consists of the sub-
routines for each month (LBL 01 ... RTN, LBL
02 ... RTN, and so on). For example, you
might want to create a message in each of
these subroutines that displays the full name
of the month and the number of days in that
month.
Many examples in the HP-42S Programming Examples and Techniques
manual (part number 00042-90020) use the programmable menu.
Local Label Searches
Searches for local labels occur only within the current program. To
find a local label, the calculator first searches sequentially downward
through the current program, starting at the location of the program
pointer. If the specified label is not found before reaching the end of
the program, the calculator continues the search from the beginning
of the program.
148 10: Programming Techniquesi
(
\
(
(¢ ¢
A local label search can consume a significant amount of time, de-
pending on the length of the current program and the distance to the
label. To minimize searching time, the calculator remembers the dis-
tance from the GTO or XEQ instruction to the specified local label.*
This eliminates the searching time for subsequent executions of that
same GTO or XEQ instruction.
Global Label Searches
When the calculator searches for a global label, the search begins with
the last global label (bottom of program memory) and proceeds up-
ward, stopping at the first label that matches the specified label. The
search is in the same order as the labels are listed in the program
catalog.
Conditional Functions
Flag tests and comparisons are conditional functions. They express a
proposition that is either true or false depending on current
conditions.
@ Executing a conditional function from the keyboard generates a
message: Yes if the proposition is currently true, or No if the prop-
osition is currently false.
@ Executing a conditional function in a program causes a program
branch using the do-if-true rule. That is, the program line immedi-
ately following the conditional is executed only if the condition is
true. If the condition is false, the next line is skipped. That is, DO
the next instruction IF the condition is TRUE.
* The distance to the label is stored internally as part of the GTO or XEQ instruction. If this
distance is greater than 4,096 bytes in either direction (128 bytes for short form lables; LBL
00 through LBL 14), the calculator cannot store the distance and a search must take place
for each execution of the instruction.
10: Programming Techniques 149Flag Tests
The following table shows the four flag test functions and how each
causes program branching (a skipped line) based on the status of the
flag being tested. (These functions are in the FLAGS menu.)
Flag Test If Flag Is Set If Flag Is Clear
Execute the next program Skip the next program line.
line.
Skip the next program line. Execute the next program
line.
Clear flag and execute the Clear flag and skip the next
next program line. program line.
Clear flag and skip the next | Clear flag and execute the
program line. next program line.
* This function can only be used with flags 00 through 35 and 81 through 99.
The following program demonstrates a subroutine call (line 03) and
flag tests (lines 02 and 08). If flag 10 is clear, FIRST is displayed, and
then SECOND. If flag 10 is set, the order of the messages is reversed.
Flag 10 Clear Flag 10 Set
J @1 LBL “FTEST"
ro @2 FS? 18 |
i @3 XEQ B —
ce @4 LBL A
@5 "FIRST"
@6 AVIEW
@7 PSE
@8 FS? 18
@9 STOP
16 LBL B
11 "SECOND"
12 AVIEW
13 PSE
14 END
--4
1
'
1
1
1
1
1
1
1
!
'
'
'
1
'
'
'
150 10: Programming TechniquesC(€€ €CCECEE
(
CECECECEECEECEEEECECEEEEEECECEE EE
Comparisons
To compare the X-register with zero:
1. Press §§(PGM.FCN) Cv) (aoa .
2. Press EBC, EREBRH , , RS, ERZBEA, or ERS
To compare the X-register with the Y-register:
1. Press §§(PGMFCN) Cv) SaaeNam .
2. Press RSM), GRRE. OREM, GRAY, GARR, or BRSVRN.
If you execute one of these functions from the keyboard, the calcu-
lator displays Yes or No, indicating the result of the test. If a program
executes one of these functions, the calculator follows the do-if-true
rule.
Testing the Data Type
The following four functions test the type of data in the X-register.
They also follow the do-if-true rule for program execution.
Function Test Proposition
REAL? Does the X-register contain a real number?
CPX? Does the X-register contain a complex number?
MAT? Does the X-register contain a matrix?
STR? Does the X-register contain an Alpha string?
Bit Test
The BIT? (bit test) function tests a single bit of a number. If the x‘ bit
of y is a 1, then the test is true. Refer to chapter 16 for more informa-
tion on the Base application and logic functions.
10: Programming Techniques 151Looping
A loop is a sequence of program instructions that starts with a label
and ends with a branch back to that label. An infinite loop is the
simplest kind. Once started, this program runs until you stop it with
(BZS) or (EXIT).
@1 LBL "LOOP"
@2 BEEP
63 GTO "LOOP"
@4 END
Looping Using Conditional Functions
When you want to perfom an operation until a certain condition is
met, but you don’t know how many times the loop must repeat, you
can create a loop with a conditional test and a GTO instruction.
For example, the following program loops until the RAN (random
number) function returns a number that is at least 0.9. That is, the
loop repeats if the random number is less than 0.9.
@1 LBL "RANDOM"
@2 LBL @1
03 8.9
@4 RAN
OS K