Interactive Manual › Chapter 16
Chapter 16: Programming
Write, edit, run and manage TI-BASIC programs: the program editor, the PRGM CTL control instructions (If, For(, While, Goto, Menu(…), the PRGM I/O input and output instructions, subroutines, and what the emulator does with assembly and link-port instructions.
Getting Started: Volume of a Cylinderp. 275
A program is a list of commands that the calculator carries out one after another, exactly as if you had typed them on the home screen. In this first example you will write a program that asks for the radius R and height H of a cylinder and then shows its volume, π×R²×H.
Write and run the CYLINDER program
You will create a program called CYLINDER with three command lines, leave the editor, and run it with a radius of 1.5 and a height of 3.
▶ Try this step-by-step on the online TI-84 Plus — keys light up as you go
- Open the PRGM menu and move right twice to the NEW tab.PRGM▶︎▶︎
- Choose 1:Create New. The
Name=prompt appears with alpha-lock already on, so the keys you press now type letters.ENTER - Type the name CYLINDER. The 2nd + ALPHA at the start (A-LOCK) is only there so that the key caps show letters: alpha-lock is already on, and pressing it again changes nothing. The keys are [C] [Y] [L] [I] [N] [D] [E] [R].2ndA-LOCKCYLINDER
- Press ENTER to accept the name. You are now in the program editor. Every command line starts with a colon.ENTER
- Paste Prompt from the PRGM I/O menu (PRGM then ▶︎ to reach I/O, then item 2), then type the variable names R and H separated by a comma. Press ENTER to start the next line.PRGM▶︎2ALPHAR,ALPHAHENTER
- Type the formula π×R²×H and store it in V: 2ndπ is π, then R, x², H, STO► and V.2ndπALPHARx²ALPHAHSTO►ALPHAVENTER
- Paste Disp (PRGM I/O item 3). Turn on alpha-lock with 2ndA-LOCK and type the quoted text "VOLUME IS". The opening quote is ALPHA", and the space between the words is ALPHA␣. Inside alpha-lock the keys are the quote, V O L U M E, the space, I S, and the closing quote. Press ALPHA to turn alpha-lock off, then type a comma and the variable V.PRGM▶︎32ndA-LOCK"VOLUME␣IS"ALPHA,ALPHAV
- Leave the editor with 2ndQUIT (QUIT). The program is saved automatically.2ndQUIT
- Press PRGM to see the PRGM EXEC menu. Its items are the names of your programs.PRGM
- Press ENTER to paste
prgmCYLINDERon the home screen.ENTER - Press ENTER again to run it. The program asks for the radius.ENTER
- Enter 1.5 for the radius.1.5ENTER
- Enter 3 for the height. The program prints
VOLUME IS, the value of V on the next line, and thenDone.3ENTER - To try other values, repeat the last three steps (paste the program name, run it, answer the prompts). On the real calculator and here, 2ndENTRY (ENTRY) recalls
prgmCYLINDERso you do not have to paste it again.
Creating and Deleting Programsp. 276
This section explains what a program is, how to create one, and how to free memory by deleting or archiving programs.
What Is a Program?p. 276
A program is a set of one or more command lines. Each line holds one or more instructions. When you run a program, the calculator performs every instruction in the order you entered them. How many programs you can keep, and how long they can be, is limited only by free memory.
Things to know about programs on OS 2.55MP:
- Programs written on OS 2.43 or earlier should still run, but may behave differently on OS 2.53MP and later. Test old programs before relying on them.
- Programs can run in either Classic or MathPrint mode.
- The shortcut menus (FRAC, FUNC, MTRX, YVAR) are available anywhere the MATH menu can be reached.
- MathPrint templates (stacked fractions, n/d, etc.) cannot be used in programs. All input and output in a program uses the one-line Classic format.
- Fractions can be used in programs, but test the program to be sure you get the results you expect.
- Spacing on the display can differ a little between Classic and MathPrint. If you prefer the Classic spacing, switch to Classic with a mode command inside the program (for example the
Classicinstruction, which you can paste from the CATALOG). - Stat Wizards give syntax help only for the functions in the DISTR DISTR menu and for
seq(in LIST OPS. Use the Catalog Help application for syntax help on everything else.
Creating a New Programp. 277
To create a program:
- Press PRGM and move to the NEW tab with ▶︎ ▶︎.
- Press ENTER to select 1:Create New. The
Name=prompt appears and alpha-lock is on. - Press a letter from A to Z, or θ, for the first character.
- Type zero to seven more letters, numbers or θ to finish the name.
- Press ENTER. The program editor opens.
- Type the program commands.
- Press 2ndQUIT (QUIT) to leave the editor and return to the home screen.
Create a one-line program called HELLO
▶ Try this step-by-step on the online TI-84 Plus — keys light up as you go
- Open the PRGM menu and go to the NEW tab.PRGM▶︎▶︎
- Select 1:Create New.ENTER
- Type the name HELLO. (Alpha-lock is already on; the A-LOCK key is included only so the keys are shown as letters.)2ndA-LOCKHELLO
- Press ENTER to open the editor.ENTER
- Paste Disp from PRGM I/O, then type the quoted text "HELLO WORLD" in alpha-lock and press ALPHA to turn alpha-lock off again.PRGM▶︎32ndA-LOCK"HELLO␣WORLD"ALPHA
- Press 2ndQUIT to quit the editor and return to the home screen.2ndQUIT
- Press PRGM. HELLO now appears on the EXEC menu.PRGM
- Press CLEAR to close the menu without choosing anything.CLEAR
Managing Memory and Deleting a Programp. 277
The calculator measures memory in bytes. To see whether there is enough room for a new program, press 2ndMEM (MEM) and choose 2:Mem Mgmt/Del. Then choose 7:Prgm to list your programs and their sizes. (Chapter 18 describes the memory screens in full.)
You can make more room by deleting programs you no longer need, or by archiving them.
Delete a program
A program called HELLO has already been created for you.
▶ Try this step-by-step on the online TI-84 Plus — keys light up as you go
- Press 2ndMEM to open the MEMORY menu.2ndMEM
- Choose 2:Mem Mgmt/Del.2
- Choose 7:Prgm. The list of programs appears with the selection cursor on the first one.7
- Move the cursor to the program you want to remove with ▲︎ and ▼︎ (it is already on HELLO), then press DEL. The calculator asks you to confirm.DEL
- Choose 2:Yes to delete. The program disappears from the list.2
- Press 2ndQUIT to return to the home screen without changing anything else.2ndQUIT
To leave the PRGM list without deleting anything, press 2ndQUIT, which returns to the home screen.
Archiving keeps a program but moves it out of RAM. In the same Mem Mgmt/Del 7:Prgm list, put the cursor on a program and press ENTER. An asterisk appears beside archived programs. Press ENTER on it again to unarchive it.
Archive and unarchive a program
▶ Try this step-by-step on the online TI-84 Plus — keys light up as you go
- Open the MEMORY menu, then 2:Mem Mgmt/Del, then 7:Prgm.2ndMEM27
- With the cursor on HELLO, press ENTER to archive it. An asterisk marks it.ENTER
- Press ENTER again to unarchive it. The asterisk goes away.ENTER
- Return to the home screen.2ndQUIT
Entering Command Lines and Executing Programsp. 278
Entering a Program Command Linep. 278
You can put on a command line any instruction or expression that you could execute from the home screen. In the program editor every new command line begins with a colon. To put more than one instruction on a single line, separate them with a colon (ALPHA:).
You can open menus while you are in the editor. To come back to the editor, either choose an item, which pastes it onto the current command line, or press CLEAR to leave the menu without choosing.
When you finish a line, press ENTER. The cursor moves to the start of the next command line.
Programs can read and change variables, lists, matrices and strings stored in memory. If a program stores a new value, that change stays in memory after the program ends. A program can also call another program as a subroutine (see Calling Other Programs as Subroutines).
Executing a Programp. 279
To run a program, start on a blank line of the home screen:
- Press PRGM to show the EXEC menu.
- Choose a program name.
prgmNAMEis pasted on the home screen, for exampleprgmCYLINDER. - Press ENTER. The busy indicator in the top right shows while the program runs.
Run a stored program
A program called HELLO that displays a greeting has been created for you.
▶ Try this step-by-step on the online TI-84 Plus — keys light up as you go
- Press PRGM to show the EXEC menu.PRGM
- Press ENTER to paste the name of the highlighted program.ENTER
- Press ENTER to run it. The greeting is shown, followed by
Done.ENTER
Breaking a Programp. 279
To stop a program while it runs, press ON. The ERR:BREAK menu appears:
- 1:Quit returns to the home screen.
- 2:Goto opens the program editor at the place where the program was interrupted.
Break a running program
A program called WAITER prints a message and then pauses, over and over. Real loops that run for a long time are interrupted the same way.
▶ Try this step-by-step on the online TI-84 Plus — keys light up as you go
- Start the program from the EXEC menu.PRGMENTERENTER
- The program is waiting at a Pause. Press ON to break it. The ERR:BREAK menu appears.ON
- Choose 2:Goto to open the program at the line that was running.2
- Press 2ndQUIT to return to the home screen.2ndQUIT
Editing Programsp. 279
Editing a Programp. 279
To edit a stored program:
- Press PRGM then ▶︎ to open the EDIT tab.
- Choose a program name. Up to the first seven lines of the program appear.
- Edit the lines: move the cursor and delete, overwrite or insert. Press CLEAR to wipe everything on the command line (the leading colon stays) and then type a new command.
| To do this | Press |
|---|---|
| Move to the start of the command line | 2nd◀︎ |
| Move to the end of the command line | 2nd▶︎ |
| Scroll down seven command lines | ALPHA▼︎ |
| Scroll up seven command lines | ALPHA▲︎ |
| Delete the character under the cursor | DEL |
| Switch between overwrite and insert | 2ndINS (INS) |
| Clear the whole command line | CLEAR |
Overwrite, insert, delete and clear in a program
The program EDITME has three lines, Disp 1+1, Disp 2+2 and Disp 3+3. You will change the middle one.
▶ Try this step-by-step on the online TI-84 Plus — keys light up as you go
- Press PRGM, move to the EDIT tab and choose EDITME.PRGM▶︎ENTER
- Move down to line 2 and jump to the end of the line.▼︎2nd▶︎
- Overwrite: press ◀︎ to put the cursor on the last 2, then type 5. The new character replaces the old one.◀︎5
- Insert: press ◀︎ to move back onto the 5, press 2ndINS (INS) to switch to insert mode, then type 1. The 1 goes in front of the 5.◀︎2ndINS1
- Delete: press DEL to delete the character under the cursor (the 5).DEL
- Clear: press CLEAR to remove everything on this command line, then paste Disp and type 9.CLEARPRGM▶︎39
- Quit the editor.2ndQUIT
- Run the program to see the result.PRGMENTERENTER
Inserting and Deleting Command Linesp. 280
To insert a new command line, put the cursor where you want the new line, press 2ndINS (INS) and then ENTER. A colon marks the new line. The easiest place to do this is at the end of the line above the one you want to add.
To delete a command line, put the cursor on it, press CLEAR to remove all the instructions and expressions on the line, and then press DEL to delete the line itself, colon included.
Insert and delete a command line
The program LINES contains Disp 1 and Disp 3. You will insert Disp 2 between them and then delete the last line.
▶ Try this step-by-step on the online TI-84 Plus — keys light up as you go
- Open LINES from the EDIT tab and jump to the end of the first line.PRGM▶︎ENTER2nd▶︎
- Press 2ndINS (INS) then ENTER. A new, empty command line (just a colon) opens below.2ndINSENTER
- Type the new command on that line.PRGM▶︎32
- Now delete the last line. Move down to it, press CLEAR to empty it, then DEL to remove the line itself.▼︎CLEARDEL
- Quit the editor.2ndQUIT
Copying and Renaming Programsp. 280
To copy every command line of one program into a new program, create the new program as described in Creating a New Program (steps 1 to 5), and then:
- Press 2ndRCL (RCL).
Rclappears on the bottom line of the editor. - Press PRGM and move to the EXEC menu.
- Choose the name of the program to copy.
prgmNAMEis pasted on the bottom line. - Press ENTER. All the command lines of that program are copied into the new one.
Copying is handy in two ways:
- to make a template out of a group of instructions you use often;
- to rename a program: copy its contents into a program with the new name, then delete the old one.
Copy HELLO into a new program
▶ Try this step-by-step on the online TI-84 Plus — keys light up as you go
- Create a new program: PRGM, NEW tab, Create New.PRGM▶︎▶︎ENTER
- Name it COPYONE.2ndA-LOCKCOPYONEENTER
- Press 2ndRCL (RCL).
Rclis shown at the bottom of the screen.2ndRCL - Open the PRGM menu and go to the EXEC tab (press ◀︎ from the first tab), then choose HELLO. Its name is pasted after
Rcl. In this list COPYONE sorts before HELLO, so HELLO is item 2.PRGM◀︎2 - Press ENTER. The lines of HELLO are copied into COPYONE.ENTER
- Quit the editor.2ndQUIT
PRGM CTL (Control) Instructionsp. 281
The control instructions decide which command runs next. They make it easy to repeat a group of commands or skip over one. To open the PRGM CTL menu, press PRGM while you are in the program editor; it is not available from the home screen. Choosing an item pastes its name at the cursor. Press CLEAR to go back to the editor without choosing.
If, While and Repeat each test a condition. Conditions are usually relational or Boolean tests (see Chapter 2), such as A<7 or N=1 and M=1. A condition is true when its value is non-zero and false when it is zero.
= is item 1, > is 3, ≥ is 4 and < is 5.Ifp. 282
:If condition:command (if true):commandTests condition. If it is true (non-zero) the next command runs. If it is false (zero) the next command is skipped. If instructions can be nested.
If A<7:A+1→AIf N=1 and M=1:Goto Z
Use If to skip a command
The program IFDEMO asks for A and displays BIG only when A is greater than 10.
▶ Try this step-by-step on the online TI-84 Plus — keys light up as you go
- Create a program called IFDEMO.PRGM▶︎▶︎ENTER2ndA-LOCKIFDEMOENTER
- Line 1: ask for A.PRGM▶︎2ALPHAAENTER
- Line 2: paste If (PRGM item 1), type A, pick
>from the TEST menu, and type 10.PRGM1ALPHAA2ndTEST310ENTER - Line 3 is the command that runs only if the test is true.PRGM▶︎32ndA-LOCK"BIG"ALPHAENTER
- Line 4 always runs, because it comes after the one command that If controls.PRGM▶︎32ndA-LOCK"DONE"ALPHA
- Quit and run the program.2ndQUITPRGMENTERENTER
- Enter 20. The test is true, so BIG is displayed.20ENTER
- Clear the screen and recall the program with 2ndENTRY (ENTRY), run it again and enter 5. This time only DONE is shown.CLEAR2ndENTRYENTER5ENTER
If-Then and If-Then-Elsep. 282
Then after an If runs a whole group of commands when the condition is true, and End marks the end of the group. Add Else to run a different group when the condition is false.
:If condition:Then:command (if true):command (if true):End:commandFollowing an If, runs the group of commands up to End when the condition is true (non-zero). If the condition is false, the group is skipped and the program continues after End.
:If condition:Then:command (if true):Else:command (if false):command (if false):End:commandFollowing If-Then, runs the group of commands between Else and End when the condition is false (zero). Only one of the two groups runs.
Choose between two groups of commands
The program SIGN asks for N and tells you whether it is negative.
▶ Try this step-by-step on the online TI-84 Plus — keys light up as you go
- Create a program called SIGN.PRGM▶︎▶︎ENTER2ndA-LOCKSIGNENTER
- Line 1: ask for N.PRGM▶︎2ALPHANENTER
- Line 2: if N is greater than or equal to 0 (TEST item 4).PRGM1ALPHAN2ndTEST40ENTER
- Line 3: Then starts the group that runs when the test is true.PRGM2ENTER
- Line 4: the command for the true case.PRGM▶︎32ndA-LOCK"ZERO␣OR␣MORE"ALPHAENTER
- Line 5: Else starts the group for the false case.PRGM3ENTER
- Line 6: the command for the false case.PRGM▶︎32ndA-LOCK"NEGATIVE"ALPHAENTER
- Line 7: End closes the If-Then-Else group. Every If-Then needs its own End.PRGM7
- Quit and run the program.2ndQUITPRGMENTERENTER
- Enter 3.3ENTER
- Clear the screen, run it again and enter −2 (use the (−) key for the minus sign).CLEAR2ndENTRYENTER(−)2ENTER
For(p. 283
:For(variable,begin,end[,increment]):command:command:End:commandLoops while counting. variable starts at begin and goes up by increment each time through the loop. increment is optional and defaults to 1; it may be negative (then end must be less than begin). end is a limit that is not to be exceeded. End marks the end of the loop. For( loops can be nested.
For(I,1,5)runs five times with I = 1, 2, 3, 4, 5For(K,10,0,⁻2)counts down 10, 8, 6, 4, 2, 0
Count with a For( loop
The program SQUARES shows the squares of 1 to 4.
▶ Try this step-by-step on the online TI-84 Plus — keys light up as you go
- Create a program called SQUARES.PRGM▶︎▶︎ENTER2ndA-LOCKSQUARESENTER
- Line 1: paste For( and give the loop variable I, the first value 1 and the last value 4.PRGM4ALPHAI,1,4)ENTER
- Line 2: the command to repeat. Show I².PRGM▶︎3ALPHAIx²ENTER
- Line 3: End closes the loop.PRGM7
- Quit and run the program.2ndQUITPRGMENTERENTER
- After the loop ends the variable holds the first value that went past the limit, so I is now 5.
Whilep. 283
:While condition:command:command:End:commandRepeats a group of commands as long as condition is true (non-zero). The condition is tested when While is reached, before the group runs, so the group may not run at all. When the condition becomes false (zero) the program continues after End. While instructions can be nested.
Repeat while a condition is true
The program DOUBLE keeps doubling N from 1 until it reaches 50 or more.
▶ Try this step-by-step on the online TI-84 Plus — keys light up as you go
- Create a program called DOUBLE.PRGM▶︎▶︎ENTER2ndA-LOCKDOUBLEENTER
- Line 1: start N at 1.1STO►ALPHANENTER
- Line 2: While N is less than 50.PRGM5ALPHAN2ndTEST550ENTER
- Line 3: double N.ALPHAN×2STO►ALPHANENTER
- Line 4: End closes the loop.PRGM7ENTER
- Line 5: show the result.PRGM▶︎3ALPHAN
- Quit and run. N goes 1, 2, 4, 8, 16, 32, 64 and then the test fails.2ndQUITPRGMENTERENTER
Repeatp. 284
:Repeat condition:command:command:End:commandRepeats a group of commands until condition is true (non-zero). It is like While, but the condition is tested when End is reached, so the group always runs at least once. Repeat instructions can be nested.
Repeat until a condition is true
The program COUNT displays 1, 2, 3 and stops when N equals 3.
▶ Try this step-by-step on the online TI-84 Plus — keys light up as you go
- Create a program called COUNT.PRGM▶︎▶︎ENTER2ndA-LOCKCOUNTENTER
- Line 1: start N at 0.0STO►ALPHANENTER
- Line 2: Repeat N equals 3 (TEST item 1).PRGM6ALPHAN2ndTEST13ENTER
- Line 3: add 1 to N.ALPHAN+1STO►ALPHANENTER
- Line 4: show N.PRGM▶︎3ALPHANENTER
- Line 5: End. The test happens here.PRGM7
- Quit and run.2ndQUITPRGMENTERENTER
Endp. 284
:EndMarks the end of a group of commands. Every For(, While and Repeat loop needs an End, and so does every If-Then and If-Then-Else group. Paste End yourself: the calculator does not add it for you.
Pausep. 284
PausePause valueSuspends the program so you can read answers or look at a graph. While it waits, the pause indicator shows in the top right corner. Press ENTER to continue. Plain Pause just waits, and shows the screen that Disp or DispGraph last put up. Pause value shows value on the current home screen, and you can scroll long values with the arrow keys.
Wait for ENTER with Pause
The program PAUSER stops twice, once with a plain Pause and once with a value.
▶ Try this step-by-step on the online TI-84 Plus — keys light up as you go
- Create a program called PAUSER.PRGM▶︎▶︎ENTER2ndA-LOCKPAUSERENTER
- Line 1: display a message.PRGM▶︎32ndA-LOCK"READY"ALPHAENTER
- Line 2: a plain Pause.PRGM8ENTER
- Line 3: Pause with a value shows the value while it waits.PRGM82+3ENTER
- Line 4: runs after the second pause.PRGM▶︎32ndA-LOCK"GO"ALPHA
- Quit and run. The program stops after READY.2ndQUITPRGMENTERENTER
- Press ENTER to continue. The second Pause shows 5 and waits again.ENTER
- Press ENTER once more. The last line runs and the program ends.ENTER
Lbl, Gotop. 285
Lbl and Goto work as a pair. Lbl gives a spot in the program a name, and Goto jumps to that spot. A label is one or two characters: A–Z, 0–99 or θ. Labels belong to the program they are in; you cannot Goto a label in another program.
Lbl labelDefines a label (one or two characters: A–Z, 0–99 or θ) that Goto can jump to.
Goto labelContinues the program at the Lbl with the same label. If no such label exists in the program, the error ERR:LABEL results.
Loop with Lbl and Goto
The program LOOPER counts to 3 by jumping back to a label.
▶ Try this step-by-step on the online TI-84 Plus — keys light up as you go
- Create a program called LOOPER.PRGM▶︎▶︎ENTER2ndA-LOCKLOOPERENTER
- Line 1: N starts at 0.0STO►ALPHANENTER
- Line 2: Lbl A marks the place to come back to.PRGM9ALPHAAENTER
- Line 3: add 1 to N.ALPHAN+1STO►ALPHANENTER
- Line 4: show N.PRGM▶︎3ALPHANENTER
- Line 5: if N is less than 3 ...PRGM1ALPHAN2ndTEST53ENTER
- Line 6: ... Goto A jumps back (only when the If is true).PRGM0ALPHAAENTER
- Line 7: runs once the loop is finished.PRGM▶︎32ndA-LOCK"DONE"ALPHA
- Quit and run.2ndQUITPRGMENTERENTER
IS>( and DS<(p. 286
IS>(variable,value):command (if answer ≤ value):command (if answer > value)Increment and skip. Adds 1 to variable. If the new value is greater than value (which may be an expression) the next command is skipped; if it is less than or equal, the next command runs. variable cannot be a system variable. IS>( is not a looping instruction.
DS<(variable,value):command (if answer ≥ value):command (if answer < value)Decrement and skip. Subtracts 1 from variable. If the new value is less than value (which may be an expression) the next command is skipped; if it is greater than or equal, the next command runs. variable cannot be a system variable. DS<( is not a looping instruction.
Skip a command with IS>( and DS<(
The program SKIPPER sets A to 3, then uses each instruction once. Only two of the Disp commands end up running.
▶ Try this step-by-step on the online TI-84 Plus — keys light up as you go
- Create a program called SKIPPER.PRGM▶︎▶︎ENTER2ndA-LOCKSKIPPERENTER
- Line 1: A starts at 3.3STO►ALPHAAENTER
- Line 2: IS>(A,3) makes A equal 4. 4 is greater than 3, so line 3 is skipped.PRGMALPHAAALPHAA,3)ENTER
- Line 3: this is skipped.PRGM▶︎32ndA-LOCK"ONE"ALPHAENTER
- Line 4: DS<(A,2) makes A equal 3. 3 is not less than 2, so line 5 runs.PRGMALPHABALPHAA,2)ENTER
- Line 5: this runs.PRGM▶︎32ndA-LOCK"TWO"ALPHAENTER
- Line 6: show A.PRGM▶︎3ALPHAA
- Quit and run. You see TWO and 3, but never ONE.2ndQUITPRGMENTERENTER
prgmp. 287
prgmnameRuns another program as a subroutine. Choosing prgm pastes it at the cursor and you then spell out the program name. This is the same as picking the program from the PRGM EXEC menu, except you can type the name of a program that does not exist yet. See Calling Other Programs as Subroutines.
Return and Stopp. 287
ReturnQuits the subroutine and goes back to the program that called it, even from inside nested loops (the loops are ended). Every subroutine has an implied Return at its end. In a main program, Return stops execution and returns to the home screen.
StopStops the program and returns to the home screen. Stop at the very end of a program is optional.
DelVarp. 287
DelVar variableDeletes the contents of variable from memory. A real-number variable goes back to 0.
Delete a variable from a program
▶ Try this step-by-step on the online TI-84 Plus — keys light up as you go
- Create a program called CLEANUP.PRGM▶︎▶︎ENTER2ndA-LOCKCLEANUPENTER
- Line 1: store 5 in A.5STO►ALPHAAENTER
- Line 2: DelVar A deletes it.PRGMALPHAGALPHAAENTER
- Line 3: show A.PRGM▶︎3ALPHAA
- Quit and run. A is back to 0.2ndQUITPRGMENTERENTER
GraphStyle(p. 288
GraphStyle(function#,graphstyle)Sets the style that a graph function is drawn in. function# is the number of the Y= function name in the current graphing mode, and graphstyle is a number from 1 to 7. Not every style is available in every graphing mode; see the Graph Styles table in Chapter 3.
GraphStyle(1,5)in Func mode sets the style of Y₁ to path (5).
| graphstyle | Style |
|---|---|
| 1 | Line |
| 2 | Thick |
| 3 | Shade above |
| 4 | Shade below |
| 5 | Path |
| 6 | Animate |
| 7 | Dot |
Set a graph style from a program
Y₁ is already set to X². The program STYLER draws it in the path style.
▶ Try this step-by-step on the online TI-84 Plus — keys light up as you go
- Create a program called STYLER.PRGM▶︎▶︎ENTER2ndA-LOCKSTYLERENTER
- Line 1: GraphStyle( for function 1, style 5 (path).PRGMALPHAH1,5)ENTER
- Line 2: DispGraph (PRGM I/O item 4) draws the graph.PRGM▶︎4ENTER
- Line 3: Pause keeps the graph on the screen until you press ENTER.PRGM8
- Quit and run. The graph appears and the program waits.2ndQUITPRGMENTERENTER
- Press ENTER to finish. The program ends with the graph still on screen; press CLEAR to return to the home screen.ENTERCLEAR
OpenLib( and ExecLib(p. 281
OpenLib(libname)No longer used. The item remains on the PRGM CTL menu for old programs, but it has no effect on a TI-84 Plus Silver Edition running OS 2.55MP. In this emulator it gives ERR:INVALID.
ExecLib libnameNo longer used. See OpenLib(. In this emulator it gives ERR:INVALID.
PRGM I/O (Input/Output) Instructionsp. 288
The I/O instructions control what goes into a program while it runs (values the user types, key presses) and what comes out (text, numbers, graphs, tables). Open the PRGM I/O menu with PRGM ▶︎ from within the program editor; it is not available from the home screen. Press CLEAR to go back to the editor without choosing an item.
Displaying a Graph with Inputp. 289
InputInput [variable]Input ["text",variable]Input [Strn,variable]With no variable, Input shows the current graph. You can move the free-moving cursor, which updates X and Y (and R and θ for PolarGC format), while the pause indicator is on. Press ENTER to continue the program. With a variable, it asks for a value (see the next sections).
Pick a point on the graph
Y₁ is set to X². The program FREEPT shows the graph, lets you move the cursor, and then displays the X value where you left it.
▶ Try this step-by-step on the online TI-84 Plus — keys light up as you go
- Create a program called FREEPT.PRGM▶︎▶︎ENTER2ndA-LOCKFREEPTENTER
- Line 1: Input with nothing after it.PRGM▶︎1ENTER
- Line 2: show the X coordinate of the cursor.PRGM▶︎3X,T,θ,n
- Quit and run. The graph appears with a cursor and the program waits.2ndQUITPRGMENTERENTER
- Press ▶︎ a few times to move the cursor.▶︎▶︎▶︎
- Press ENTER. The program resumes and shows the X value of the cursor.ENTER
Storing a Variable Value with Inputp. 289
With a variable, Input shows a ? prompt while the program runs. The variable can be a real or complex number, a list, a matrix, a string or a Y= function. Type a value (it can be an expression) and press ENTER. The value is evaluated, stored in the variable, and the program carries on.
You can show your own prompt text (or the contents of a string variable Strn) of up to 16 characters instead of the ?: Input "text",variable or Input Strn,variable.
Ask for a value with Input
The program TIMES asks for A with the default prompt and for B with your own prompt text, then shows A×B.
▶ Try this step-by-step on the online TI-84 Plus — keys light up as you go
- Create a program called TIMES.PRGM▶︎▶︎ENTER2ndA-LOCKTIMESENTER
- Line 1: Input A uses the plain
?prompt.PRGM▶︎1ALPHAAENTER - Line 2: a prompt with your own text, "SECOND", stored in B.PRGM▶︎12ndA-LOCK"SECOND"ALPHA,ALPHABENTER
- Line 3: show the product.PRGM▶︎3ALPHAA×ALPHAB
- Quit and run. The program shows a
?and waits.2ndQUITPRGMENTERENTER - Enter 6.6ENTER
- Enter 7. The product is displayed.7ENTER
Use a string variable as the prompt
The program ASKN stores a prompt in Str1 and passes it to Input, then doubles the number you enter.
▶ Try this step-by-step on the online TI-84 Plus — keys light up as you go
- Create a program called ASKN.PRGM▶︎▶︎ENTER2ndA-LOCKASKNENTER
- Line 1: store the text in Str1. Type the quoted text, press STO►, then choose Str1 from VARS → 7:String → 1:Str1.2ndA-LOCK"HOW␣MANY?"ALPHASTO►VARS71ENTER
- Line 2: Input with the string as the prompt, storing the answer in N.PRGM▶︎1VARS71,ALPHANENTER
- Line 3: show double the answer.PRGM▶︎3ALPHAN×2
- Quit and run. Your text is the prompt.2ndQUITPRGMENTERENTER
- Enter 21.21ENTER
Ask for a list with Input
The program LISTIN reads a list into L₁. The braces are part of what you type.
▶ Try this step-by-step on the online TI-84 Plus — keys light up as you go
- Create a program called LISTIN.PRGM▶︎▶︎ENTER2ndA-LOCKLISTINENTER
- Line 1: Input L₁ (2ndL1 is L₁).PRGM▶︎12ndL1ENTER
- Line 2: show the list.PRGM▶︎32ndL1
- Quit and run.2ndQUITPRGMENTERENTER
- Type the list including its braces (2nd{ and 2nd}) and press ENTER.2nd{1,2,32nd}ENTER
Promptp. 290
Prompt variableA[,variableB,…,variable n]While the program runs, Prompt shows each variable in turn followed by =?. At each prompt, type a value or expression and press ENTER. The values are stored and the program resumes. Y= functions are not valid with Prompt.
Prompt for two variables
The program ADDER asks for A and B and prints their sum.
▶ Try this step-by-step on the online TI-84 Plus — keys light up as you go
- Create a program called ADDER.PRGM▶︎▶︎ENTER2ndA-LOCKADDERENTER
- Line 1: Prompt A,B.PRGM▶︎2ALPHAA,ALPHABENTER
- Line 2: show the sum.PRGM▶︎3ALPHAA+ALPHAB
- Quit and run. The first prompt is
A=?.2ndQUITPRGMENTERENTER - Type 4 and press ENTER. Now it asks for B.4ENTER
- Type 2+3, an expression. It is evaluated before it is stored.2+3ENTER
Displaying the Home Screen and Values (Disp)p. 290
DispDisp [valueA,valueB,valueC,…,value n]With nothing after it, Disp shows the home screen. Follow it with Pause if you want to look at the home screen during a program. With values, it displays each one. A variable shows its current value; an expression is evaluated and the result is shown on the right side of the next line; text inside quotation marks is shown on the left side of the current line. The store arrow → cannot be used in the text. If Pause comes after Disp, the program waits so you can read the screen, and ENTER resumes it.
Disp "A IS",A,A²+1
Display text, variables and expressions
The program SHOWME stores 5 in A and displays a message, A, and the expression A²+1.
▶ Try this step-by-step on the online TI-84 Plus — keys light up as you go
- Create a program called SHOWME.PRGM▶︎▶︎ENTER2ndA-LOCKSHOWMEENTER
- Line 1: store 5 in A.5STO►ALPHAAENTER
- Line 2: one Disp with three items, separated by commas.PRGM▶︎32ndA-LOCK"A␣IS"ALPHA,ALPHAA,ALPHAAx²+1
- Quit and run. The text is on the left of its line; the values are on the right of the lines below.2ndQUITPRGMENTERENTER
DispGraph and DispTablep. 291
DispGraphDisplays the current graph. If Pause comes after DispGraph, the program waits so you can look at the graph; press ENTER to resume.
DispTableDisplays the current table. The program waits so you can look at it; press ENTER to resume.
Show the graph from a program
Y₁ is set to X². The program SHOWG draws the graph and waits.
▶ Try this step-by-step on the online TI-84 Plus — keys light up as you go
- Create a program called SHOWG.PRGM▶︎▶︎ENTER2ndA-LOCKSHOWGENTER
- Line 1: DispGraph (PRGM I/O item 4).PRGM▶︎4ENTER
- Line 2: Pause keeps the graph on the screen.PRGM8
- Quit and run. The graph is displayed and the program waits.2ndQUITPRGMENTERENTER
- Press ENTER to resume. The program ends, leaving the graph on screen; press CLEAR to go back to the home screen.ENTERCLEAR
Show the table from a program
Y₁ is set to X². The program SHOWT displays the table and then a message.
▶ Try this step-by-step on the online TI-84 Plus — keys light up as you go
- Create a program called SHOWT.PRGM▶︎▶︎ENTER2ndA-LOCKSHOWTENTER
- Line 1: DispTable (PRGM I/O item 5).PRGM▶︎5ENTER
- Line 2: runs once you resume.PRGM▶︎32ndA-LOCK"BACK"ALPHA
- Quit and run. The table is displayed and the program waits.2ndQUITPRGMENTERENTER
- Press ENTER to resume. The message is displayed.ENTER
Output(p. 291
Output(row,column,"text")Output(row,column,value)Displays text or a value on the current home screen starting at row (1 to 8) and column (1 to 16), writing over whatever was there. Expressions are evaluated and shown according to the current mode settings. Matrices are shown in entry format and wrap to the next line. The store arrow → cannot be used in the text. On a Horiz split screen the largest row is 4. It is usual to put ClrHome in front of Output(.
Place text and values with Output(
The program PLACER clears the screen, writes HI at row 3, column 6, and puts the value of 2+3 at row 5, column 1.
▶ Try this step-by-step on the online TI-84 Plus — keys light up as you go
- Create a program called PLACER.PRGM▶︎▶︎ENTER2ndA-LOCKPLACERENTER
- Line 1: ClrHome (PRGM I/O item 8) clears the screen.PRGM▶︎8ENTER
- Line 2: text at row 3, column 6.PRGM▶︎63,6,2ndA-LOCK"HI"ALPHA)ENTER
- Line 3: a value at row 5, column 1.PRGM▶︎65,1,2+3)ENTER
- Line 4: Pause keeps the screen up until you press ENTER.PRGM8
- Quit and run.2ndQUITPRGMENTERENTER
- Press ENTER to end the program.ENTER
getKeyp. 292
getKeyReturns the code of the last key pressed, or 0 if no key has been pressed. Use it inside a loop to react to keys, for example when writing a game. You can press ON at any time to break the program.
getKey→Kstores 105 in K if ENTER was pressed.
| Row | Keys and their codes |
|---|---|
| 1 | Y= 11, WINDOW 12, ZOOM 13, TRACE 14, GRAPH 15 |
| 2 | 2nd 21, MODE 22, DEL 23, ◀︎ 24, ▲︎ 25, ▶︎ 26 |
| 3 | ALPHA 31, X,T,θ,n 32, STAT 33, ▼︎ 34 |
| 4 | MATH 41, APPS 42, PRGM 43, VARS 44, CLEAR 45 |
| 5 | x⁻¹ 51, SIN 52, COS 53, TAN 54, ^ 55 |
| 6 | x² 61, , 62, ( 63, ) 64, ÷ 65 |
| 7 | LOG 71, 7 72, 8 73, 9 74, × 75 |
| 8 | LN 81, 4 82, 5 83, 6 84, − 85 |
| 9 | STO► 91, 1 92, 2 93, 3 94, + 95 |
| 10 | 0 102, . 103, (−) 104, ENTER 105 |
Read a key press with getKey
The program KEYTEST loops until you press a key, then shows its code.
▶ Try this step-by-step on the online TI-84 Plus — keys light up as you go
- Create a program called KEYTEST.PRGM▶︎▶︎ENTER2ndA-LOCKKEYTESTENTER
- Line 1: K starts at 0.0STO►ALPHAKENTER
- Line 2: Repeat K keeps looping until K is not zero.PRGM6ALPHAKENTER
- Line 3: getKey (PRGM I/O item 7) stores the key code in K.PRGM▶︎7STO►ALPHAKENTER
- Line 4: End.PRGM7ENTER
- Line 5: show the code.PRGM▶︎3ALPHAK
- Quit and run. The program now waits for a key.2ndQUITPRGMENTERENTER
- Press the 5 key. Its code is 83.5
ClrHome and ClrTablep. 292
ClrHomeClears the home screen while the program runs.
ClrTableClears the values in the table while the program runs (the entries of a table whose independent variable is set to Ask).
GetCalc(p. 292
GetCalc(variable[,portflag])Gets the contents of variable from another TI-84 Plus and stores it in the same variable on the receiving calculator. The variable can be a real or complex number, list element, list name, matrix element, matrix name, string, Y= variable, graph database or picture. By default the USB port is used if a cable is connected, otherwise the I/O port. portflag 0 means use the USB port if connected, 1 means use the USB port, and 2 means use the I/O port.
Get( and Send(p. 293
Get(variable)Gets data from a CBL 2 or CBR and stores it in variable on the receiving TI-84 Plus. The variable can be a real number, list element, list name, matrix element, matrix name, string, Y= variable, graph database or picture.
Send(variable)Sends the contents of variable to a CBL 2 or CBR. You cannot use it to send to another TI-84 Plus. The variable can be a real number, list element, list name, matrix element, matrix name, string, Y= variable, graph database or picture, or a list of elements.
Calling Other Programs as Subroutinesp. 293
Any stored program can be called from another program as a subroutine. Put the name of the program to call on a line by itself. You can enter the name in either of two ways:
- Press PRGM, move to the EXEC tab and choose the program.
prgmNAMEis pasted at the cursor. - Choose prgm from the PRGM CTL menu (item D) and then type the name of the program.
When the line prgmNAME is reached, the next command to run is the first command of the second program. When it reaches a Return, or runs off its end (an implied Return), execution continues with the command after the call in the first program.
Notes about calling programs:
- Variables are global: both programs see and change the same variables.
- Labels used with Lbl and Goto are local to the program they are in. A label in one program is not known to another, and you cannot Goto a label in a different program.
- Return leaves the subroutine and goes back to the calling program, even when it is inside nested loops.
Call a subroutine and return from it
The program SUB already exists: it displays IN SUB, then does Return, then has a line that never runs. You will write MAIN, which calls it.
▶ Try this step-by-step on the online TI-84 Plus — keys light up as you go
- Create a program called MAIN.PRGM▶︎▶︎ENTER2ndA-LOCKMAINENTER
- Line 1: display a message.PRGM▶︎32ndA-LOCK"START"ALPHAENTER
- Line 2: call SUB. Press PRGM, go to the EXEC tab with ◀︎, and choose SUB (item 2, since MAIN sorts before it). The name is pasted as
prgmSUB.PRGM◀︎2ENTER - Line 3: display a message after the call.PRGM▶︎32ndA-LOCK"BACK"ALPHA
- Quit and run MAIN, the first program on the EXEC menu.2ndQUITPRGMENTERENTER
Running an Assembly Language Programp. 294
The TI-84 Plus can run programs written in assembly language. They usually run much faster than programs written with the built-in editor and give much finer control of the calculator. When you download an assembly program, it is stored with your other programs and appears on the PRGM menus. You can send it over the link (Chapter 19) and delete it from the MEM MGMT/DEL screen (Chapter 18).
Asm(assemblyprgmname)Runs an assembly language program. Paste Asm( from the CATALOG (2ndCATALOG) and then add the program name, for example with prgm from the PRGM EXEC menu.
AsmPrgmIdentifies an assembly language program. It must be the first line of the program.
AsmComp(prgmASM1,prgmASM2)Compiles an assembly language program that is written in ASCII hex (the first program) and stores the machine-code version in a new program (the second).
AsmComp(prgmASM1,prgmASM2)
To compile an assembly program that you have written:
- Write the program as usual (see Creating a New Program) but make AsmPrgm the first line.
- On the home screen press 2ndCATALOG (CATALOG) and choose AsmComp( to paste it.
- Press PRGM to show the EXEC menu.
- Choose the program to compile. It is pasted on the home screen.
- Press ,, then choose prgm from the CATALOG.
- Key in the name you want for the output program. The name must be new, not a copy of an existing program name.
- Press ) to finish the sequence. The arguments are in this order:
AsmComp(prgmASM1,prgmASM2). - Press ENTER to compile the program and create the output program.
| Instruction | Comments |
|---|---|
| AsmComp(prgmASM1,prgmASM2) | Compiles an assembly language program written in ASCII and stores the hex version |
| AsmPrgm | Identifies an assembly language program; must be entered as the first line of an assembly language program |