TI-BASIC
Encyclopedia
TI-BASIC is the unofficial name of a BASIC
BASIC
BASIC is a family of general-purpose, high-level programming languages whose design philosophy emphasizes ease of use - the name is an acronym from Beginner's All-purpose Symbolic Instruction Code....

-like language built into Texas Instruments (TI)
Texas Instruments
Texas Instruments Inc. , widely known as TI, is an American company based in Dallas, Texas, United States, which develops and commercializes semiconductor and computer technology...

's graphing calculator
Graphing calculator
A graphing calculator typically refers to a class of handheld calculators that are capable of plotting graphs, solving simultaneous equations, and performing numerous other tasks with variables...

s, including the TI-83 series
TI-83 series
The TI-83 series of graphing calculators is manufactured by Texas Instruments.The original TI-83 is itself an upgraded version of the TI-82. Released in 1996, it is one of the most used graphing calculators for students...

, TI-84 Plus series
TI-84 Plus series
The TI-84 Plus is a graphing calculator made by Texas Instruments which was released in early 2004. There is no original TI-84, only the TI-84 Plus and TI-84 Plus Silver Edition models. It is an enhanced version of the TI-83 Plus. The key-by-key correspondence is relatively the same, but the 84...

, TI-89 series
TI-89 series
The TI-89 and the TI-89 Titanium are graphing calculators developed by Texas Instruments. They are differentiated from most other TI graphing calculators by their computer algebra system, which allows symbolic manipulation of algebraic expressions...

, TI-92 series
TI-92 series
The TI-92 series of graphing calculators are a line of calculators produced by Texas Instruments. They include: the TI-92 , the TI-92 Plus , and the Voyage 200 . The design of these relatively large calculators includes a QWERTY keyboard...

 (including Voyage 200), TI-73, and TI-Nspire. TI usually doesn't refer to the language by name, but the name TI-BASIC has been used occasionally in developer documentation.

For many applications, it is the most convenient way to program any TI calculator, since the capability to write programs in TI-BASIC is built-in. Assembly language
Assembly language
An assembly language is a low-level programming language for computers, microprocessors, microcontrollers, and other programmable devices. It implements a symbolic representation of the machine codes and other constants needed to program a given CPU architecture...

 (often referred to as "asm") can also be used, and C
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

 compiler
Compiler
A compiler is a computer program that transforms source code written in a programming language into another computer language...

s exist for translation into assembly: TIGCC
TIGCC
TIGCC is a software development environment which allows developers to program and compile A68K assembly, GNU assembly, and C code for the Motorola 68000 series Texas Instruments graphing calculators...

 for Motorola 68000
Motorola 68000
The Motorola 68000 is a 16/32-bit CISC microprocessor core designed and marketed by Freescale Semiconductor...

 (68k) based calculators, and Z88DK
Z88DK
Z88DK is a Small-C-derived cross compiler for a long list of Z80 based computers. The name derives from the fact that it was originally developed to target the Cambridge Z88...

 for Zilog Z80
Zilog Z80
The Zilog Z80 is an 8-bit microprocessor designed by Zilog and sold from July 1976 onwards. It was widely used both in desktop and embedded computer designs as well as for military purposes...

 based calculators. However, both of them are cross-compilers, not allowing on-calculator programming. TI-BASIC is considerably slower than the assembly language (because it has to be interpreted), making it better suited to writing programs to quickly solve math problems or perform repetitive tasks, rather than playing games or doing graphic intensive tasks. Some math instruction books even provide 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.

Syntax

The syntax of all versions of TI-BASIC are somewhat different from typical BASIC implementations. The language itself has some basic structured programming
Structured programming
Structured programming is a programming paradigm aimed on improving the clarity, quality, and development time of a computer program by making extensive use of subroutines, block structures and for and while loops - in contrast to using simple tests and jumps such as the goto statement which could...

 capabilities, but makes limited to no use of or allowance for white space or indentation. It is also dependent on a somewhat non-standard character set
TI calculator character sets
- TI-86 :- TI-89/92 Series :The 68k calculators use a character set similar to Latin-1 except that most of the control characters are replaced with mathematical symbols or Greek letters. All characters are printable except the null character....

, with specific characters for assignment (the right "STO" arrow, not readily available in most character sets), square
Square root
In mathematics, a square root of a number x is a number r such that r2 = x, or, in other words, a number r whose square is x...

 and cube roots, and other mathematical symbols, as well as tokenized entry and storage for keywords. All statements begin with a colon, which also functions as a statement separator within lines.

Expressions use infix notation
Infix notation
Infix notation is the common arithmetic and logical formula notation, in which operators are written infix-style between the operands they act on . It is not as simple to parse by computers as prefix notation or postfix notation Infix notation is the common arithmetic and logical formula notation,...

, with standard operator precedence. Many statements include their arguments in parentheses, similar to the syntax used for mathematical functions. The assignment syntax is unusual; rather than using a let statement or an equals sign, TI-BASIC uses a right-arrow "STO" operator with the syntax: source → destination.

Control flow

Control flow
Control flow
In computer science, control flow refers to the order in which the individual statements, instructions, or function calls of an imperative or a declarative program are executed or evaluated....

 statements include if-then-else blocks, for loop
For loop
In computer science a for loop is a programming language statement which allows code to be repeatedly executed. A for loop is classified as an iteration statement....

s, while loop
While loop
In most computer programming languages, a while loop is a control flow statement that allows code to be executed repeatedly based on a given boolean condition. The while loop can be thought of as a repeating if statement....

s, and repeat loops
Do while loop
In most computer programming languages, a do while loop, sometimes just called a do loop, is a control flow statement that allows code to be executed repeatedly based on a given Boolean condition. Note though that unlike most languages, Fortran's do loop is actually analogous to the for loop.The...

, though no switch statement
Switch statement
In computer programming, a switch, case, select or inspect statement is a type of selection control mechanism that exists in most imperative programming languages such as Pascal, Ada, C/C++, C#, Java, and so on. It is also included in several other types of languages...

s. Unusual for a high level language, TI-BASIC implementations include IS> (Increment and Skip if Greater Than) and DS< (Decrement and Skip if Less Than) statements, constructs generally associated with assembly language
Assembly language
An assembly language is a low-level programming language for computers, microprocessors, microcontrollers, and other programmable devices. It implements a symbolic representation of the machine codes and other constants needed to program a given CPU architecture...

s. Sections of programs can be labeled
Label (programming language)
A label in a programming language is a sequence of characters that identifies a location within source code. In most languages labels take the form of an identifier, often followed by a punctuation character . In many high level programming languages the purpose of a label is to act as the...

; however, particularly on the Z80 models, the labels function primarily as destinations for GOTO
Goto
goto is a statement found in many computer programming languages. It is a combination of the English words go and to. It performs a one-way transfer of control to another line of code; in contrast a function call normally returns control...

 statements rather than as program or block labels.

Availability of functions and subroutines depends on the implementation; the versions available on the TI-82-descended calculators do not even support a GOSUB
GOSUB
GOSUB is a command in many versions of the BASIC computer programming language. A GOSUB statement jumps to a line elsewhere in the program. That line and the following lines up to a RETURN are used as a simple kind of a subroutine without parameters or local variables.The GOSUB command may be used...

-like function, though it is possible to call programs from within each other and share variables between programs. TI-89/92-based designs can have access to shared functions, essentially programs capable of returning a value.

Data types

TI-BASIC is a strongly and dynamically-typed language. Available data types differ considerably between the 68k and Z80 versions. It is not possible to create user-defined data types without using a library written in assembly. Lists are often used as a replacement for structs
Record (computer science)
In computer science, a record is an instance of a product of primitive data types called a tuple. In C it is the compound data in a struct. Records are among the simplest data structures. A record is a value that contains other values, typically in fixed number and sequence and typically indexed...

.

68k

  • Integers, which can store a large amount of data. The 68k calculators can store very large numbers, as high as , with perfect accuracy.
  • Real numbers, using decimal floating point
    Decimal floating point
    Decimal floating point arithmetic refers to both a representation and operations on decimal floating point numbers. Working directly with decimal fractions can avoid the rounding errors that otherwise typically occur when converting between decimal fractions and binary fractions.The...

    . These store up to 14 significant digits depending on the calculator model.
  • Complex numbers, implemented as pairs of reals.
  • Strings
    String (computer science)
    In formal languages, which are used in mathematical logic and theoretical computer science, a string is a finite sequence of symbols that are chosen from a set or alphabet....

  • Lists, which are one-dimensional arrays
    Array data type
    In computer science, an array type is a data type that is meant to describe a collection of elements , each selected by one or more indices that can be computed at run time by the program. Such a collection is usually called an array variable, array value, or simply array...

     of numbers which support elementwise operations. On the 68k calculators, elements can be integers, reals, complex numbers, strings or expressions.
  • Matrices
    Matrix (mathematics)
    In mathematics, a matrix is a rectangular array of numbers, symbols, or expressions. The individual items in a matrix are called its elements or entries. An example of a matrix with six elements isMatrices of the same size can be added or subtracted element by element...

    , with elements subject to the same restrictions in lists
  • Symbolic expressions
    Symbolic computation
    Symbolic computation or algebraic computation, relates to the use of machines, such as computers, to manipulate mathematical equations and expressions in symbolic form, as opposed to manipulating the approximations of specific numerical quantities represented by those symbols...

    , unique to the 68k series.


Data types that cannot be directly manipulated (typing only their name on a line would result in an error) include:
  • Pictures
  • Data
  • Programs
  • Functions

TI-83/84 (Z80)

  • Numerical variables
    Variable (programming)
    In computer programming, a variable is a symbolic name given to some known or unknown quantity or information, for the purpose of allowing the name to be used independently of the information it represents...

    , including A - Z and Θ
    Theta
    Theta is the eighth letter of the Greek alphabet, derived from the Phoenician letter Teth...

    (theta). These allow real number
    Real number
    In mathematics, a real number is a value that represents a quantity along a continuum, such as -5 , 4/3 , 8.6 , √2 and π...

    s or complex number
    Complex number
    A complex number is a number consisting of a real part and an imaginary part. Complex numbers extend the idea of the one-dimensional number line to the two-dimensional complex plane by using the number line for the real part and adding a vertical axis to plot the imaginary part...

    s (implemented as pairs of reals) to be stored in floating point
    Floating point
    In computing, floating point describes a method of representing real numbers in a way that can support a wide range of values. Numbers are, in general, represented approximately to a fixed number of significant digits and scaled using an exponent. The base for the scaling is normally 2, 10 or 16...

     format. Values may range from 1E-99 to 1E99 with up to ten digits of accuracy. The limit of 27 variables, however, may be expanded through the use of lists or matrices, as a programmer can define each element in a list or matrix as a unique real variable and reference it accordingly.
  • Strings
    String (computer science)
    In formal languages, which are used in mathematical logic and theoretical computer science, a string is a finite sequence of symbols that are chosen from a set or alphabet....

    , including Str0 - Str9. These may store any number of characters or even function names, as long as there is available memory.
  • Lists, including L1 - L6. These are essentially one-dimensional arrays
    Array data type
    In computer science, an array type is a data type that is meant to describe a collection of elements , each selected by one or more indices that can be computed at run time by the program. Such a collection is usually called an array variable, array value, or simply array...

     used to store a real or complex number into each of their elements. The dimension
    Dimension
    In physics and mathematics, the dimension of a space or object is informally defined as the minimum number of coordinates needed to specify any point within it. Thus a line has a dimension of one because only one coordinate is needed to specify a point on it...

     of a list, its number of elements, may range from 1 to 999, although available memory
    Random-access memory
    Random access memory is a form of computer data storage. Today, it takes the form of integrated circuits that allow stored data to be accessed in any order with a worst case performance of constant time. Strictly speaking, modern types of DRAM are therefore not random access, as data is read in...

     may be a limiting factor
    Limiting factor
    A limiting factor or limiting resource is a factor that controls a process, such as organism growth or species population, size, or distribution. The availability of food, predation pressure, or availability of shelter are examples of factors that could be limiting for an organism...

    . When a list's dimension is set lower than it previously was, elements at the end are cut off. When set higher, extra elements at the end are filled with zeros. Dimensions are set by storing a valid number into the dim( of the list name. The default lists are named L1–L6, but custom lists can be created. This is done by setting dimension of a list referenced with the L token (accessible by pressing [2nd]+[LIST(STAT)], under the OPS menu as item B:), followed by a name ranging from 1 to 5 characters
    Character (computing)
    In computer and machine-based telecommunications terminology, a character is a unit of information that roughly corresponds to a grapheme, grapheme-like unit, or symbol, such as in an alphabet or syllabary in the written form of a natural language....

     that begins with an uppercase letter (A–Z) or Θ. Individual elements of lists can be accessed by placing the element number in parentheses after the list name.
  • Matrices
    Matrix (mathematics)
    In mathematics, a matrix is a rectangular array of numbers, symbols, or expressions. The individual items in a matrix are called its elements or entries. An example of a matrix with six elements isMatrices of the same size can be added or subtracted element by element...

    , including [A] - [J]. Their elements are subject to the same restrictions as lists. Their dimensions may be defined up to 99x99 elements, although, again, available memory will limit this. It is not possible to create user-defined matrices, so only the ten built in ones may be utilized.
  • Equation variables, including Y0 - Y9, r1 - r6, and u, v, w. These are essentially strings which store equations. A powerful feature of this data type is that strings (containing numbers or even variables to be substituted) will be solved when assigned to one of these variables. Then the respective variable can be accessed again to retrieve the numerical result. This provides a work around to change strings into numbers, since there is no built in function to do so.


Data types that cannot be directly manipulated (typing only their name on a line would result in an error) include:
  • Pictures (Pic0 - Pic9)
  • Programs (Prgm)
  • Graph databases (GBD0 - GBD9)


Examples:
:16→A "Store the value of 16 into variable A."
:B+1→B "Increment the relative value of B by 1."
:−1.3+4.9i→Θ "Store the value of negative 1.3 plus 4.9i into variable theta (Θ)."

:25→dim(L1) "Set the dimension of list L1 to 25, so it has 25 elements."
:999→dim(L6) "Set the dimension of list L6 to its maximum of 999."
:0→dim(L2) "Will return an error because zero is not a valid list dimension."

:Disp L1(4) "Yields the value of the fourth element of List 1."
:15→dim(LMYLST) "Creates a new list named MYLST with 15 default elements (filled with zeros)."
:9→LMYLST(3) "Stores the value of nine into the third element of list MYLST."
:Disp LMYLST(3) "Displays '9'."

Variables

Flexibility in the use of variables varies widely by the calculator model. The 68k calculators allow all variable names to have up to eight alphanumeric (including Greek
Greek alphabet
The Greek alphabet is the script that has been used to write the Greek language since at least 730 BC . The alphabet in its classical and modern form consists of 24 letters ordered in sequence from alpha to omega...

) characters. Furthermore, variables can be grouped into "folders", or made local
Local variable
In computer science, a local variable is a variable that is given local scope. Such a variable is accessible only from the function or block in which it is declared. In programming languages with only two levels of visibility, local variables are contrasted with global variables...

 to a program (by declaring them with the Local statement). In contrast, on the TI-83, the programmer can create lists whose names are up to five characters. All other data types are limited, such as the 27 real or complex variables (A-Z and Θ), and a number of predefined variable names of other types (e.g., matrices have to be one of the ten variables [A]-[J]). Also, all variables are global.

Comments

The 68k calculators allow programs to include single-line comments
Comment (computer programming)
In computer programming, a comment is a programming language construct used to embed programmer-readable annotations in the source code of a computer program. Those annotations are potentially significant to programmers but typically ignorable to compilers and interpreters. Comments are usually...

, using ©
Copyright symbol
The copyright symbol, or copyright sign, designated by © , is the symbol used in copyright notices for works other than sound recordings . The use of the symbol is described in United States copyright law, and, internationally, by the Universal Copyright Convention...

 as a comment symbol. If a comment appears as the first line after the "Prgm" statement, it is displayed in the status bar when the program is selected in the catalog; such comments are often used to document the names or types of parameters.

Z80 programmers often start lines with " (double quotation mark) to denote a comment - the line is interpreted as a string, and not executed. Note that, because of this, the string value of the comment will be assigned to the Ans variable.

Functions

The 68k version of TI-BASIC allows creating user-defined functions. Functions have the same syntax as programs except that they use the Func...EndFunc keywords instead of Prgm...EndPrgm, and that they are not allowed to use instructions that perform I/O, modify non-local variables, nor call programs. However, functions can still be non-pure
Pure function
In computer programming, a function may be described as pure if both these statements about the function hold:# The function always evaluates the same result value given the same argument value...

 because they can call built-in functions such as getTime, getKey, or rand
Pseudorandom number generator
A pseudorandom number generator , also known as a deterministic random bit generator , is an algorithm for generating a sequence of numbers that approximates the properties of random numbers...

.

All functions have a return value, which in the absence of an explicit Return statement is the last expression evaluated.

Third-party language extensions

Third-party applications, in chronological order Omnicalc, xLib, Celtic, and Doors CS, have overloaded TI-BASIC functions on the Z80 calculators to provide additional language functionality. The third-party libraries overload the sum, real, det and identity functions, which are handled and interpreted by their respective applications. Among the extra functions are fast shape-drawing routines, sprite and tilemap tools, program and VAT modification and access abilities, GUI construction features, and much more, most of which are ordinarily restricted to use by assembly programmers. All of the functions require that an application like Doors CS 7.0 be present on the user's calculator, sometimes considered a detraction to the use of the libraries.

Examples

These examples are slightly TI-83-series biased. For example, "ClrHome" would be "ClLCD" on the TI-85
TI-85
The TI-85 was a graphing calculator made by Texas Instruments based around the Zilog Z80 microprocessor. Designed in 1992 as TI's second graphing calculator , it has since been replaced by the TI-86, which has also been discontinued....

 and TI-86
TI-86
The TI-86 is a programmable graphing calculator introduced in 1997 and produced by Texas Instruments. The TI-86 uses the Zilog Z80 microprocessor. It is partially backwards-compatible with its predecessor, the TI-85....

.

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 programming purposes, however, this command is essentially useless.

Hello world

The following program, when executed, will display the phrase "HELLO, WORLD!
Hello world program
A "Hello world" program is a computer program that outputs "Hello world" on a display device. Because it is typically one of the simplest programs possible in most programming languages, it is by tradition often used to illustrate to beginners the most basic syntax of a programming language, or to...

":

Z80 Series
PROGRAM:HELLOWLD
:ClrHome
:Disp "HELLO, WORLD!"

68k Series
hellowld
:Prgm
: ClrIO
: Disp "Hello, World!"
:EndPrgm

Lists and loops

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:

Lists

TI-82 Series Z80

PROGRAM:LISTS
:Input "NUMBER OF VARS? ",A
:If A<1 or fPart(A)
:Stop
:For(N,1,A)
:Input "VAR ",B
:B→L1(N)
:End
:L1

TI-85/86 Z80
PROGRAM:Lists
:Input "Number of variables? ",A
:If A<1 or fPart A
:Stop
:For(N,1,A)
:Input "Var ",B
:B→L1(N)
:End
:L1

68k Series

lists
:Prgm
: Local n,i,c
: {}→list
: Input "Number of variables?",n
: For i,1,n
: Input "Variable #"&string(i),c
: c→list[i]
: EndFor
:EndPrgm

In addition, lists are important for saving save game data and highscore data in programs. This is better than storing highscore or save game information as a variable, as variables are commonly changed during calculations performed by the user. Lists on the TI-82 cannot have custom names (L1 through L6 are preprogrammed). The TI-85 and TI-86 do not have the ability to handle a variable name with subscripts. The TI-81 is completely unable to handle lists.

Elaborations

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(L1)", subtracting one from it, and implementing another While loop which would subtract from the "dim(L1)" 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<1 or fPart(A)" statement checks to see if the variable A is a negative number, is zero or a non-integer. If so, the program is stopped by the Stop 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 L1. In the For loop
For loop
In computer science a for loop is a programming language statement which allows code to be repeatedly executed. A for loop is classified as an iteration statement....

, N is first set to 1, then the For loop will continue while N is less than or equal to A. After every iteration of the For loop, N will increase by 1. Every time the For loop is executed, an input is asked for, and the element is added to the end of the list, and saved. By this time, the list L1 should have a dim(L1) = A (the length of the list is A) and be ready for manipulation.

Counting

Z80 Series
PROGRAM:COUNTING
:ClrHome
:10^10→B
:For(A,1,B)
:Output(1,1,A
:End

68k Series
counting
:Prgm
: Local a,b
: 10^10→b
: For a,1,b
: Disp a
: EndFor
:EndPrgm

Explanation of Z80 Counting Code

This program defines the variable B, as (10^10). In the Z80 version, a "For loop" is established, which will store each successive number from 1 through B (10^10) in variable A.

The program then outputs the data currently stored in Variable A, to character space 1,1 in the screen (Top left corner).

A Clrhome refresh is not required, because each successive "A" variable which is outputted to character space (1,1) will replace the previous value on the screen which was there.

This loop will continue until the value of variable "A" is equivalent to the value of Variable "B", at which point the program will end.

Recursion

Recursion is possible. A program can be called from within itself or from within another program.

Z80 Series

PROGRAM:FACTUI
:"A user interface for FACT"
:Prompt X
:1→A:"An accumulator of sorts. The answer will be stored here."
:prgmFACT

PROGRAM:FACT
:If X=0
:Then
:Disp A
:Stop
:End
:XA→A
:X-1→X
:prgmFACT

68k Series

factui
:Prgm
: Local fact, n
: Define fact(x)=Func
: If x=0
: Return 1
: Return x*fact(x-1)
: EndFunc
: Input "Input a number", n
: Disp "n! = "
: Disp fact(n)
:EndPrgm

Functions

The 68k series makes a distinction between programs and functions. Functions are just like programs except that they do not allow statements with side effects (like Input or Disp, nor modifying non-local variables), and they return a value, which in the absence of an explicit Return statement is the last expression evaluated.

fact(x)
:Func
: If x=0
: Return 1
: If x<0
: Return undef
: x*fact(x-1)
:End Func

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK