TI-Basic Z80 Programming/Hello, World!
Opening and Navigating the Program Editor
[edit | edit source]To begin coding TI-BASIC on your calculator, you must use the program editor. This allows you to edit, manage, and run your programs. To access it, press PRGM NEW ENTER. Then, type in a short name for your program. The names for programs must follow these rules:
- Must include only uppercase letters and numbers, where the first character must be a letter
- Cannot include any other tokens, such as symbols or math functions
- Maximum length of 8 tokens long
Press ENTER, and an empty program will appear. In the following example, the program has been named EXAMPLE
:
PROGRAM:EXAMPLE
To navigate the program editor, use the arrow keys to move the cursor, which is represented by a blinking black box. Press ENTER to move the cursor down a line, or to create a new line if the cursor is at the bottom-most line. To insert a line at any point, move the cursor to the end of the line above where the new line should be inserted. Then press 2ND [INS] ENTER. To clear a line, press CLEAR. Press DEL on any empty line to delete it.
Always, the first line (PROGRAM:EXAMPLE
) on the screen shows the name of the program. It is not a line in the code, but rather a header to show the name of the current program. Press ENTER. Now, a new line on the program editor is created:
PROGRAM:EXAMPLE
In TI-Basic, colons (:
) are used to signify new lines.
- Colons are automatically placed by the calculator when creating a new line. These colons cannot be deleted, except by deleting the line itself.
- Manually adding a colon (ALPHA [:]) also signifies a new line. These colons can be deleted.
To run a program, you need to first exit the program editor. Press 2ND [QUIT] to return to the home screen. Press PRGM and use the up and down arrows to select your program. Now, press ENTER twice: once to paste it to the home screen and second to execute it.
To stop a program during execution, press the ON key and an error will be thrown, stopping the program.
Hello, world!
[edit | edit source]Now that you have learned how to navigate and perform simple edits on a program, now we will program our first program: the "hello world." This simple program tells the calculator to display the text HELLO, WORLD!
on the screen.
PROGRAM:HLLOWRLD
- ClrHome
- Disp "HELLO, WORLD!"
Now, let's break down each line of this program and understand how it works.
- ClrHome
Every new line in a TI-BASIC program automatically starts with a colon. It's how the calculator knows when a line ends and a new line begins. ClrHome (PRGM I/O 8) is the instruction that clears the home screen, erasing any text or numbers that may have been on it.
- Disp "HELLO, WORLD!"
Disp (PRGM I/O 3) displays a variable, value, or string to the screen. If the screen is full, it will scroll down a line. If the string is more than 16 characters, Disp will only show the first 15 of them, followed by an ellipse (…). During the execution of the program, you will not be able to scroll and see the rest of the line if the 16 character limit is exceeded. Strings are displayed left-aligned, and values are displayed right-aligned.
In order to add quotation marks ("), press ALPHA +.
In this example, the string HELLO, WORLD!
is printed to the screen.
{{{1}}}
If you attempt to recreate the above example and get an output of 0 or an error, ensure that you have wrapped "HELLO, WORLD!" in quotes. If you do not, each letter will be treated as a variable and will multiply the variables together.
Also, be sure you didn't manually type the commands using the ALPHA key. Use the options presented when pressing PRGM. |
Alternate Method
[edit | edit source]Another command offered for printing to the screen is the Output (PRGM I/O 6) command. This command offers more arguments to specify where on the screen to print.
Output(row,column,"text") Output(row,column,value)
- Where row is the vertical positioning of the output. A value of 1 prints on the first row, etc.
- Where column is the horizontal positioning of the output. A value of 1 prints on the first column, etc.
- Where "text" or value is the text or value to be displayed to the screen.
Here's how to use this command in the "hello world" program. It prints HELLO, WORLD!
at row 1 column 1:
- ClrHome
- Output(1,1,"HELLO, WORLD!")
This program will result in the same output.
{{{1}}}
On some old versions of the Operating System on the TI-83+, the calculator may crash if there are many other programs. You should update the operating system, or (preferably) program on the computer and then transfer to the calculator. |
You try it!
[edit | edit source]Try these examples to practice the Disp and Output commands.
Poem
[edit | edit source]Use the Disp commands to print a simple poem to the screen. Your poem should be 7 or fewer lines to fit on the screen (if you try to print an 8th line, the first line will move off the screen).
Solution
|
---|
This example poem will print to the screen: {{{1}}} |
Centered Text
[edit | edit source]Using Output, replicate the following output exactly. You will need to use the command more than once.
{{{1}}}
Solution
|
---|
|