Congratulations on downloading Jeff Glenn's Programmable Calculator app!
And you only have to enter the prt instruction. The eof is automatic. You see how easy this can be. Don't get scared, the rest is easy, too.
The Programmable Calculator app has two displays: the larger main display and the smaller status display. The main display is where you see program steps as well as program and manual calculation results. For instance, "Hello, world!" in the sample program above will be displayed in the main display. The status display shows one of three states the calculator is in: STOPPED, RUNNING, and INPUT .
Under the right side of the main display is the PROG/RUN switch. This switch changes the calculator between Program mode and Run mode. You enter and edit programs in Program mode and run programs in Run mode. You also perform manual operations in Run mode.
You'll see that there are 4 different colors of keys. The colors help group the keys into related functions. The f key enables alternate functions for other keys, like a shift. The alternate functions are shown in the same gold color right above the key, e.g., the TIME function over the IN key.
The calculator uses a virtual keyboard to accept textual input for file names and for the PRT instruction. This keyboard has three sets of keys that are selected using the symbol and shift keys. The three sets of keys look like this:
To enter upper case letters, touch the shift up key. The upper case keys will be shown for the next key selected and then it will return to the lower case keys. If you want to enter more than one upper case letter, touch the shift lock key. When you are done entering upper case letters, touch the shift down key.
To enter symbols, touch the symbols key. When you're done entering symbols, touch the alphabetic key.
To erase the last character entered, touch the clear key. When you are finished entering all your text, touch the key.
The calculator has four types of storage:
Program steps, Registers, and Labels are all numbered from zero. You can use up to 10 Registers (0 .. 9), plus the Accumulator, and up to 10 Labels (0 .. 9). Files are identified by names.
Some functions are directly accessible as a single key touch, like IN . The rest of the functions are accessible by first touching the f key and then the key under the desired function, like TIME. Once a function is selected, by either method, the calculator will accept that function. Some functions cause program instructions to be stored and others are used to edit the program. The second group also includes saving programs to your device's memory and loading existing programs from your device's memory.
NOTE: It doesn't matter whether your device has an SD card for its memory or it is emulated by your device as part of its built-in memory. Your programs are stored in a "Programs" folder on your device.
The functions mostly fall into one of several categories: Logical, Input/Output, Jump, Store, Math, Edit, File, and Other.
Category | Functions | Description |
---|---|---|
Logical | <, ≤, =, ≠, >, ≥, DSZ | Compares the value in the Accumulator with the parameter. If true, the next instruction is executed. Otherwise the next instruction is skipped. Usually, the next instruction will be GTO. DSZ decrements a Register and skips the next instruction when its value is zero. |
Input/Output | IN, OUT, PRT | Allows input of numeric values and output of numeric and string values. |
Jump | LBL, GTO | Enables program execution to repeat or skip. |
Store | SET, CLR, STO, RCL, XCH | Sets the Accumulator to a constant or Register value or saves the Accumulator in a Register. XCH swaps the values in the Accumulator with a Register. |
Math | −, +, ×, ÷ | Performs arithmetic operations with the Accumulator and constants or Registers. |
Edit | RESET, FIRST, ↑, LAST, ↓, DEL | Allows you to clear the calculator, view the steps of a program, and delete steps. |
File | SAVE, LOAD, ERASE | Saves programs to files, loads programs from files, and erases files. |
Other | TIME, SLEEP, EEX, REM, R/S, Error, Menu | Performs functions that don't fit into the other categories. |
NOTE: The = key is also used to (a) indicate that a parameter is a number, (b) indicate the end of a numeric parameter, (c) confirm you want to reset the calculator, and (d) complete pending manual operations.
So you see that some functions correspond to instructions that can be stored and executed in a program while others are used to view and edit a program. Some functions are used for both.
Executable instructions can have different parameters (or none at all). Some instructions can have different types of parameters, e.g., + can have none (meaning the Accumulator), a digit (meaning a Register), or a literal number like -2.75. When entering an instruction, the calculator will prompt for the parameters that can be used, e.g., A[.], R[0-9], number[=]:
Labels are entered and displayed similarly to Registers, i.e., as a single digit.
New instructions are inserted into the current program, after the displayed instruction.
TIP: If you make a mistake entering an instruction, we suggest you move to the incorrect instruction and insert the correct one after it. Then move up and delete the incorrect one. This leaves the incorrect instruction as a placeholder until you're sure you have entered the correct instruction and in the correct location. You can move through your program using the FIRST, ↑, LAST, and ↓ functions.
NOTE: Instruction names are stored and displayed as lower case alphabetic strings. Their function may be shown on the calculator in upper case or as a symbol like "+".
All of the functions are described in detail in the following table.
Key | Display | Type | Parameter | Description |
---|---|---|---|---|
f | f | Shift | None | Selects alternate key functions. |
≤ | le | Logical | Constant or Register | Executes the next instruction if the Accumulator is less than or equal to the parameter. |
≠ | ne | Logical | Constant or Register | Executes the next instruction if the Accumulator is not equal to the parameter. |
≥ | ge | Logical | Constant or Register | Executes the next instruction if the Accumulator is greater than or equal to the parameter. |
< | lt | Logical | Constant or Register | Executes the next instruction if the Accumulator is less than the parameter. |
= | eq | Logical | Constant or Register | Executes the next instruction if the Accumulator is equal to the parameter. |
> | gt | Logical | Constant or Register | Executes the next instruction if the Accumulator is greater than the parameter. |
DSZ | dsz | Logical | Register | Decrement and Skip on Zero: Subtracts 1 from the Register and skips the next instruction if the Register is zero. |
IN | in | Input/Output | Register | Input: Pauses the running program and waits for a number to entered. When R/S is touched, the number is stored in the specified Register and the program continues running. (A ← Input) |
OUT | out | Input/Output | Register | Output: Appends the value in the specified Register to the display. The program does not stop. See the NOTE below. |
PRT | prt | Input/Output | String or nothing | Print: When no parameter is specified, the display is cleared. When a string parameter is specified, it is appended to the display. The program does not stop. See the NOTE below. |
LBL | lbl | Jump | Label | Label: Marks a location in the program where a GTO or DSZ can jump to. |
GTO | gto | Jump | Label | Go To: Causes the program to jump to the location of the specified LBL instruction and continue from there. |
SET | set | Store | Number | Stores the specified number in the Accumulator. (A ← Number) |
CLR | clr | Store | None | Clear: Sets the Accumulator to zero. (A ← 0.0) |
STO | sto | Store | Register | Store: Sets the specified Register to the value in the Accumulator. (A → R) |
RCL | rcl | Store | Register | Recall: Sets the Accumulator to the value of the specified Register. (A ← R) |
XCH | xch | Store | Register | Exchange: Swaps the values of the specified Register and the Accumulator. (A ↔ R) |
− | sub | Math | None, Constant, or Register | Subtracts the value of the specified Register from the Accumulator. (A ← A − R) |
+ | add | Math | None, Constant, or Register | Adds the value of the specified Register to the Accumulator. (A ← A + R) |
× | mul | Math | None, Constant, or Register | Multiplies the Accumulator by the value of the specified Register. (A ← A × R) |
÷ | div | Math | None, Constant, or Register | Divides the Accumulator by the value of the specified Register. (A ← A ÷ R) |
RESET | N/A | Edit | None | Clears the current program and Registers. |
FIRST | N/A | Edit | None | Moves to the first instruction in the program. |
↑ | N/A | Edit | None | Moves to the previous instruction in the program. If at the first one, moves to the last one. |
LAST | N/A | Edit | None | Moves to the last instruction in the program. |
↓ | N/A | Edit | None | Moves to the next instruction in the program. If at the last one, moves to the first one. |
DEL | N/A | Edit | None | Deletes the displayed instruction from the program. |
SAVE | N/A | File | Name or New | Saves the program to a file in the device's memory. |
LOAD | N/A | File | Name | Loads the program from a file in the device's memory. |
ERASE | N/A | File | Name | Erases a stored program file from the device's memory. |
TIME | tim | Other | None | Sets the Accumulator to the current time. The time used is the number of milliseconds since the device was booted and includes deep sleep. This time is guaranteed to be monotonic and continues to tick even when the device is in power saving modes. It can be used to calculate elapsed time. (A ← Time) |
SLEEP | slp | Other | None, Constant, or Register | Causes the program to wait for the specified number of milliseconds before continuing. This is useful for displaying intermediate results without stopping the program. Using a Register allows you to calculate the sleep time or to easily use the same value in several places. |
EEX | E | Other | None | Enter Exponent: Appends an exponent (i.e., power of 10) to the number being entered. |
REM | rem | Other | None or String | Remark: Enters a comment in the program. This is useful as the first instruction to show the name of the program. Remarks are skipped over during execution, i.e., they are No Operation (NOP) instructions. |
R/S | stp | Other | None | Run/Stop: When executed in a program, it causes the program to stop running. When used manually, this key will stop a program that is running and start a program that is stopped. When the key is touched after the f key, it displays the app's option menu. This is for devices with no hardware menu key. |
Error | err | Other | None or String | Indicates that an unrecognized instruction was included in the program. This can occur when loading a program that was created outside the calculator app (e.g., with a text editor). The string parameter shows the whole unrecognized instruction and any parameter. Errors are skipped over during execution. |
Menu | N/A | Other | None | Causes the app's option menu to be displayed. |
NOTE: The PRT and OUT instructions can be used together to mix text and values, e.g.:
Recall that PRT with no parameter clears the display. When run, the program will display something like this:
TIP: When you touch the PRT key, a virtual keyboard opens. To enter a prt instruction with no parameter, touch the key without typing anything.
You have options for getting feedback when you touch the calculator's keys. The Key Options are available from the options menu. They look like this:
When "Sound" is checked, the calculator beeps each time you touch a key. When "Vibrate" is checked, the calculator vibrates each time you touch a key. This is also called haptic feedback. Both options can be used together if you like. Be aware that some devices do not support vibration.
OK, you have all the details but if you're like me, you need to see an example. You probably noticed that this calculator has basic arithmetic operations, but no square root. Well, not to worry, square roots can be computed using a method that is easy to implement on your Programmable Calculator app! This is described in detail in "Methods of computing square roots" but here are the essentials:
We are going to use successive approximation to get better and better estimates of the square root of a number. Since we are actually using a computer (your device) with a finite representation of real numbers, we can calculate the best possible estimate for your device by repeating enough times. We don't have to repeat that many times because this method converges quickly.
The equation we will solve is: x(i+1) = ½ (x(i) + S/x(i))
In words, our next estimate, x(i+1), is calculated as ½ the sum of our current estimate, x(i), and our number, S, divided by our current estimate. We replace our current estimate with our new estimate and repeat. In our example program, we will repeat a fixed number of times. You could also compare successive estimates until the difference is small enough for your needs.
When creating programs, it is a good idea to write down the values you will be using and assign them to Registers. You may also want to write down your program before you enter it into the app so you can check it over. Here are some notes for our program:
S | – The number for which we'll calculate the square root |
x(0) | – Our initial approximation (guess) for which we'll use S ÷ 2 |
x(i) | – Our successive approximation (estimate) |
limit | – The number of times we will repeat |
We will assign the Registers like this:
R(0) | – S |
R(1) | – x(i) |
R(2) | – limit (e.g., 10) |
And here is our program, with notes:
00 rem "Square Root" | A remark for identification |
01 set 10.0 | A ← Limit |
02 sto 2 | A → R(2) |
03 prt | Clear the display |
04 prt "Number?" | Print a prompt for the number |
05 in 0 | Input S → R(0) |
06 rcl 0 | A ← R(0) |
07 div 2.0 | Our initial guess is S ÷ 2.0 |
08 lbl 0 | Label(0) |
09 prt | Clear the display |
10 out | Output A, i.e., x(i) |
11 slp 1000.0 | Sleep 1 second to see the estimate |
12 sto 1 | Store x(i) in R(1) |
13 rcl 0 | A ← R(0), i.e., S |
14 div 1 | A ← A ÷ R(1), i.e., S/x(i) |
15 add 1 | A ← A + R(1), i.e., x(i) + S/x(i) |
16 div 2.0 | A ← A ÷ 2.0, i.e., ½ (x(i) + S/x(i)) |
17 dsz 2 | Decrement R(2), skip on zero |
18 gto 0 | Go To Label(0), i.e., repeat |
19 eof | The end |
TIP: You can tell whether a parameter is a Register or a literal by the presence of a decimal point and a fractional part. For example, add 1 means add Register 1 while div 2.0 means to divide by the literal 2.0.
Hopefully, this helps to see how a program is written and what it does. This Square Root program is available for download.
The number sequence: 1, 1, 2, 3, 5, 8, etc., named for Leonardo Fibonacci, appears all around in nature. The Fibonacci program to display this sequence is provided as a bonus.
While Body Mass Index (BMI) is not the best measure of a person's weight, it does give you a sense of whether your weight is alright, too much, or (heaven forbid) too little. The BMI Range program calculates the healthy weight range for your height.
You may wonder why the lyrics of a song are the basis for a calculator program. Well, this particular song inspired over 1500 programs! As a brief history, in 1994, someone posted the complete lyrics for this song to a humor mailing list. Some recipient of the post complained that this was a waste of bandwidth and that the lyrics could be generated with only six lines of BASIC. The original poster slighted C++ programmers so the site maintainer posted a version in C++ and that opened the floodgates for programmers from all over the world to post their own versions in many assorted languages. You can read more about this history and see all the different versions on the 99 Bottles of Beer website. The 99 Bottles of Beer program for your Programmable Calculator is provided as another bonus. If you are too impatient to wait, preview the final display or change the 99.0 in step 4.
One extra note should be mentioned about the "Hello, world!" program given above. While the simple, one-step program will display "Hello, world!", it will be appended to whatever is already on the display. In practice, you'll probably want a simple prt instruction first to clear the display.
The calculator stores its programs as text files that can be transferred and edited on other systems. If you want to do this, be sure to save the program files with Unix format end of lines.
If you have ideas or requests for enhancements, please send an email to jeff@igram.org and we'll see what we can do. We are planning on enhancements and we welcome your feedback.
Thank you for your support!