TI-Basic Z80 Programming/Hello, World!

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Opening and Navigating the Program Editor[edit]

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 the PRGM button, use the key until the NEW tab is highlighted, then press ENTER. Then, type in a short name for your program. Naming guidelines include:

  • Must include only uppercase letters and numbers, where the first character must be a character
  • 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:

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. 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) shows the name of the program. Press ENTER. Now, a new line on the program editor is created:

PROGRAM:EXAMPLE
:
:

A colon signifies a new line of the program.

  • 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]

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 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-justified, and values are displayed right-justified.

In this example, the string HELLO, WORLD! is printed to the screen.

HELLO, WORLD!

Alternate Method[edit]

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:

:ClrHome
:Output(1,1,"HELLO, WORLD!")

This program will result in the same output.

HELLO, WORLD!

You try it![edit]

Try these examples to practice the Disp and Output commands.

Poem[edit]

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 screeen).

Centered Text[edit]

Using Output, replicate the following output exactly. You will need to use the command more than once.

 WELCOME TO THE
  TI-BASIC Z80
    WIKIBOOK


Previous: Necessary Items
Next: Basic Variables
Table of Contents: TI-Basic Z80 Programming