# TI-BASIC

*48*pages on

this wiki

**TI-BASIC** is the unofficial name of a BASIC-like language built into Texas Instruments (TI)'s graphing calculators. (Except for the TI-85 and TI-86 variants, TI only refers to it as the calculators' "extensive programming capability".) Though the TI-BASIC name has stuck, the syntax is actually rather different from almost all standard BASIC implementations, sometimes resembling other languages such as PILOT or even Forth.

It is the most convenient way to program any TI calculator, since the capability to write programs in TI-BASIC are built-in. Assembly language (often referred to as "asm") can also be used, and C compilers exist for translation into assembly: TIGCC for Motorola 68000 based calculators, and Z88DK for Zilog Z80 based calculators. However, both of them are in fact cross-compilers, not allowing on-calculator programming. Although TI-BASIC is considerably slower than assembler and consequently is not very good for programming fast applications and games, it is very useful for quickly writing programs to solve math problems (formulae, etc) and for performing repetitive tasks, with some math instruction books even providing programs in TI-BASIC (usually for the widespread variant used by the TI-82/83/84 series).

Although it is somewhat minimalist compared to programming languages used on computers, TI-BASIC is nonetheless an important factor in the programming community. Because TI graphing calculators are required for advanced mathematics classes in many high schools and universities, TI-BASIC is often the first glimpse many students have into the world of programming. Learning to program in TI-BASIC is a relatively easy task, encouraging potential programmers to explore the field of computer science.

## ExamplesEdit

Before we go to programming

we should BACK TO THE BASIC

there is a simple question, i bet you can't answer it!

i want to know how simple processor work?

how we make a simple gadget that only show/print A?

These examples are slightly TI-83-series biased. For example, "ClrHome" would be "ClLCD" on the TI-85 and TI-86.

An entirely different command is required to clear the screen in the TI-89. Since output is generally displayed on the ProgramIO screen, the "ClrIO" command is required to clear the output screen. There exists a "ClrHome" command on the TI-89, and it performs its function - namely, clearing the Home screen. For the purpose of programs, however, this command is essentially useless (yet it is invaluable in the programming of functions).

### Hello worldEdit

The following program, when run, will print the phrase `"HELLO WORLD!"`

:

Z80 Series

PROGRAM:HELLOWLD :Disp "HELLO, WORLD!"

68000 Series

hellowld() :Prgm :Disp "Hello, World!" :EndPrgm

### BounceEdit

The following program, when run, will print out the phrase `"Bounce"`

which bounces around the screen.

Z80 Series

PROGRAM:BOUNCE :ClrHome :1→X :1→Y :1→S :1→T :While 1 :Output(Y,X,"BOUNCE") :X+S→X :Y+T→Y :If X<2 or X>10 :Then :-S→S :End :If Y<2 or Y>7 :Then :-T→T :End :ClrHome :End

#### ExplanationEdit

- The ClrHome command clears the "home screen" of the calculator, then the variables we'll use: X, Y, S, and T are initialised to 1.
- The
`While 1`

statement begins an infinite loop. - The string "BOUNCE" is displayed on the calculator at the co-ordinates given by X and Y.
- X and Y are both incremented by one (because S and T both equal 1). If the string were output at this point it would be (1,1) offset the last location. If X and Y are beyond the size of the screen (16,8) then the value to increment is negative, so the string will now be output (-1,-1) of the last location.
- The home screen is cleared again. Omitting this statement means "BOUNCE" fills the screen.
- Finally, the
`End`

statement delimits the`While`

block above, it doesn't actually end the program.

The program, like all programs written in TI-BASIC, can be halted by pressing the On button of the calculator once.

### Lists and LoopsEdit

The significance of lists in terms of programming is quite often overlooked. Needless to say, lists, in combination with loops, are quite useful in creating programs that can handle much more than a set number of inputs. That is:

#### ListsEdit

Z80 Series

PROGRAM:LISTS :Input "NUMBER OF VARIABLES ",A :If A<1 or fPart(A) :Return :Input "VAR ",B :{B}→L1 :For(N,2,A) :Input "VAR ",B :augment(L1,{B})→L1 :End :L1

#### ElaborationsEdit

Essentially, this program can be used to compile a list containing an arbitrary number of elements, which could then be implemented in a larger program that would break up the list and put each element to use. For instance, if we were to create a polynomial equation solver, we would use the technique noted above to compile all the coefficients into a list. Under the guidelines of the Rational Root Theorem, we would implement the first and last elements into a program to be factored and paired (and put into another list). To finish, we would create another While loop which would take the list with the factored elements, raise them to the appropriate power (this can be done by finding the "dim(L_{1})", subtracting one from it, and implementing another While loop which would subtract from the "dim(L_{1})" with intervals of 1), multiplying the result to the elements of the original list, adding the new results, and checking to see if the sum (of the new result) is equal to 0.

The "If A<0 or fPart(A)" statement checks to make sure the variable A is not a negative integer, if so, the program is stopped by the Return statement. If the condition is not true, then the program continues on to the rest of the code. The first variable is used to define L_{1}. In the For( loop, only the commands between For(N,2,A) and the first End are considered. Every time the For( loop is executed, an input is asked for, and the element in augmented into a list, and saved. By this time, the list L_{1} should have a dim(L_{1}) = A and be ready for manipulation.

#### CountingEdit

Z80 Series

Program:Counting :10^10→B :For(A,1,B) :Disp A :End