|
Programming
|
This section is targeted toward experienced programmers who would like to learn how to write programs with optimal efficiency. The basic concepts and elementals of the languages presented here are beyond the scope of this guide. If you'd like to learn Z80 Assembly, click here. If you'd like to learn TI-83 Plus BASIC, refer to chapter 16 of the TI-83 Plus guidebook.
Programming is a fun and educational concept. If you plan on being a professional programmer, you will need to master a concept called efficiency. Efficiency involves two things - memory and time.
|
|
|
TI-83 Plus BASIC
|
WARNING: In order to avoid confusion, many small pictures are used in this section to display the special TI-83 Plus characters that are not standard on a computer. Many TI-BASIC related sites use, for example, '->' to indicate the store command. This site uses pictures that look much like the real characters, that way you will know exactly what to type on your calculator. However, your browser may have not loaded all the pictures. Any of these small pictures that did not load should instead say "NOT LOADED", though sometimes the pictures may not load, and they won't say anything.
If you see the words NOT LOADED anywhere on this page, do the following:
Internet Explorer users:Right-click where it says NOT LOADED, and then select "Show Picture"
Netscape users:Click on "Reload". Repeat as necessary until all pictures are shown.
|
Note on TI-BASIC
|
First of all, you must understand that writing very complicated programs or games, such as Pacman!, or something along those lines, the TI-BASIC language is simply the worst language to write it in. TI-BASIC does, however, exert some advantages over Z80 Assembly, such as easy access to all the mathematical functions. In most cases, writing math programs is best done in BASIC, so long as time consumption is not a factor. But for simplifying radical programs, or prime tester programs, Z80 assembly is undoubtedly the better choice.
But for those of you who insist on using TI-BASIC, this guide to optimal efficiency should serve fruitful. If you're a persistent BASIC programmer, you should at least be efficient, which is what this guide is for.
|
|
Time Consumption
|
As I'm sure you already know, time consumption in 83 Plus BASIC programs is a HUGE problem. There many obstacles to dodge in order to use less time while still consuming the same memory. Several things to keep in mind are that:
If statements generally are very time consuming.
- Use
Repeat or While instead of Lbl and Goto whenever possible.
- If you ever need to make it return to the beggining of the program, use the
prgm command to re-execute the same program instead of using labels.
- If certain commands and tricks save memory, they generally also save time.
|
|
Memory Consumption
|
There are numerous tricks used to conserve memory. It is suggested that you always go by this list to ensure maximum efficiency in your programs.
Please note that this list of optimization tricks is almost if not entirely complete. I constructed this list over a week or so, but I might have forgotten or left out a few things. I will continue to add to this list if any omitted tricks arise. If you discover something that I left out, please e-mail me.
General Optimizations
- You never need any closing parentheses, brackets, or double quotes that are at the end of a line of code. This is true if and only if these closing brackets are at the end of the line of code. For an example:
- :Text(0,0,"HELLO WORLD")
- :Disp 6(X+(2/3)+[A](3,4))
In this example, the line of code should be optimized to:- :Text(0,0,"HELLO WORLD
- :Disp 6(X+(2/3)+[A](3,4
- In response to rule #1, you do not need to include any closing parentheses, brackets, or double quotes that precede the store (
) command. Here's an example:- :"HELLO WORLD"
Str1- :6(X+(2/3)+[A](3,4))
Y The code should be optimized to:- :"HELLO WORLD
Str1- :6(X+(2/3)+[A](3,4
Y
- When you have
If statements that have only one nested line of code, you do not need to include Then and End statements. So,- :If X=3
- :Then
- :Disp "HELLO WORLD
- :End
should be optimized to:- :If X=3
- :Disp "HELLO WORLD
- Never use any colons to place lines of code on the same line. Each time you do this, your wasting one whole byte. Consider this:
- :If X=3:Disp "GOODBYE
should be optimized to- :If X=3
- :Disp "GOODBYE
- There are, however, certain instances where it is more efficient to place lines of code on the same line. This is only true with the
DelVar command. The DelVar command does not need a colon after it to indicate a new line of code. This means that the command immediately following the DelVar statement should be placed immediately after the argument. Here's an example:- :DelVar X
- :ClrDraw
- :ClrHome
This should be optimized into- :DelVar XClrDraw
- :ClrHome
Likewise, if you have multiple DelVar statements, they should also be placed on the same line. This trick will work when deleting any type of variable except named lists. So when using the DelVar command to delete a list, unless it's one of the six built in lists (L1,L2...L6), the code following it must be placed on a new line.
- Never use:
- :ClrList L1
Instead, use:- :DelVar L1
DelVar does the same thing as ClrList, except it allows to keep the code after it on the same line, hence using less memory.
- Never use:
- :0
X Instead, use:- :DelVar X
Any undefined variable is automatically initialized to 0 when it is first used. In addition, DelVar allows to keep the code after it on the same line, hence using less memory.
- Never use:
- :Disp "PRESS ENTER
- :Pause
The Pause commands can take strings as an argument for display:- :Pause "PRESS ENTER
- Try to reorder groups of expressions so that expressions with the most closing brackets are at the end of the line. This way, you will save memory by not having to include those closing brackets. For an example:
- :If (Y+2)/(X-(Z/3))=4 and C=3
- :Goto A
This should be reordered into this:- :If C=3 and 4=(Y+2)/(X-(Z/3
- :Goto A
- Often times BASIC programmers like to set the window range to decimal values, so that lines and other graphics commands can be performed easily. If you ever need to do this, do not use
ZInteger. ZInteger sets the window so that it has negative values, so everytime you want to type a coordinate that will appear in the 2nd, 3rd of 4th quadrant, you will have to use the negative sign. Eventually, these negative signs will accumulate and take up much space. Most programmers instead use this:- :0
Xmin- :94
Xmax- :0
Ymin- :62
Ymax However, you can save 2 bytes if you use this instead:- :0
Xmin- :1
 X- :0
Ymin- :1
 Y
Optimizing through Equality Tests Operations and Boolean Values
In order for the following section to make sense, you must understand the Boolean priniciples. Boolean priniciples are a universal system of evaluating expressions as being either true or false. An expression is false if it evaluates to 0. If the expression's evaluation is nonzero, the expression is true. All the program control commands on the calculator work the same way. The If statement tests the expression, and if the expression is true, it will execute the nested instructions. Likewise, the While command will loop while the given expression is true. Repeat will loop until the given expression is true. This means that the expression you provide for the Repeat command is the the false-expression.
- Since any expression that evaluates into a nonzero value is true, you don't need to ever use
X 0 as the expression for a If or While command. Instead, just use X. Consider this example:- :While X
0- :If Y
0- :Goto A
- :Y+1
Y- :End
Should be optimized into:- :While X
- :If Y
- :Goto A
- :Y+1
Y- :End
- In addition to boolean values, there are boolean operators. These operators are
and, or (inclusive OR), xor (exclusive OR), and not. You should never use:- :If (X=3 and Y
3) or (Y=3 and X 3- :Goto A
Instead, use the XOR operator:- :If X=3 xor Y=3
- :Goto A
- Never use
If X=0, use If not(X. This will save you one byte.
- Sometimes you can reorder a list of
If statements so that the last possible outcome would not even need an If statement. For example: - :If not(X
- :Goto A
- :If X=1
- :Goto B
- :If X=2
- :Goto C
This should be reordered into:- :If X=2
- :Goto C
- :If X
- :Goto B
- :Goto A
In this example, the technique used is, of coarse, only useful because that specific section of the program is either going to goto label A, B, or C, depending on the value of X. So this trick will not always be applicable.
- The most efficient programming techinique is a concept called equality test operations. It involves using boolean values to suppliment for values in an expression. In other words, it's a much quicker and efficient alternative to
If statements. This example should explain how this technique works:- :If X=3
- :Y+1
Y This should be optimized into:- :Y+(X=3
Y You can also perform any mathematical operations on the boolean values to produce the desired result. Consider this:- :If X=3
- :Y+5
Y- :If J=6
- :Y-(X-2
Y Use equality test operations:- :Y+5(X=3)-(X-2)(J=6
Y
- When you have two or more expressions seperated by
or, you can sometimes add the boolean values instead of using or. Consider this example:- :If X=3 or sin(Y) or not(Y
This line of code tests to see if the sine of Y is true (nonzero), or X is true, or Y=0. But it would save memory to do it this way:- :If X=3 or sin(Y)+not(Y
This way, you save one byte by adding the boolean values of sin(Y) and not(Y) instead of using or. This trick generally only serves useful if there are two or more expressions that have no relational or equality operator.
- If you ever are comparing two unary expressions with a boolean operator, you'll find that many times you won't even need the boolean operator. For instance:
- :If X and Y
- :Goto A
- :If X or Y
- :Goto B
This should be optimized into this:- :If XY
- :Goto A
- :If X+Y
- :Goto B
Since all the expressions being compared are unary (have no releational operator, like =,>,<,etc), the boolean operator and and or are only comparing the boolean values. or is true if at least one of the boolean values is 1. So adding the boolean values will produce the same effect. and returns true only if both the values are 1. So multiplying the boolean values will suffice, because if either one of the values is 0, the product of both values will also be 0.
Token Optimizations
The TI-83 Plus commands and operators are not stored in the ROM as string, but as what's called a token. Every function available to the user is a token, If, prgm, +, sin(, etc. are all tokens. Tokens are very efficient because they use only 1 or 2 bytes, regardless of how many characters long the token is. If the calculator were to instead use strings, putting the Repeat command into your program would increase your program by 7 bytes, and If would increase it by 3, whereas with tokens they only use 1 byte each. Though most tokens use 1 byte, there are several that use 2 bytes. By learning which tokens use 1 byte and which ones use 2 bytes, you can use certain tricks to use less memory in your programs. Below are several tricks involving token usage.
- Certain words or strings that you might use in your programs may already be stored in a token. For instace, you should never type out the word "Pause", use the
Pause token instead. In this case, you would have saved 7 bytes! Here is a list of other tokens that could be used to substitute strings used in your programs:- This list will be added soon!
Optimizing through Mathematics
You'll find that using some of the mathematical functions available in TI-BASIC can often times use less memory than a conventional method. Below are some tricks to incorporate when you encounter such situations.
- When you have a number containing two or more zeros, it may use less memory to use the
operator. This operator will multiply the number on it's left (1 if no number is given) times 10 to the number given on the right. This is called scientific notation, and it becomes very useful when expressing large numbers. Here's some examples:- :100
X- :50000
Y Use instead:- :
2 X- :5
4 Y
- Sometimes you might want to use a variable to set the exponent of a number. In a case such as this, the calcualtor won't allow to use
X, so you would have to use 10^X. But let's further optimize:- :10^X
A Instead of typing out 10^, consider this:- :
^(X A Using the ^( operator will save you 2 bytes.
- Never use:
- :Disp 1/X
- :Disp Y^-1
Use the operator:- :Disp X
 - :Disp Y

- Never use:
- :Disp (A/B)
 - :1/(A/B
Y Simplify using the inverse property:- :Disp B/A
- :B/A
Y
- Never use:
- :-A+B
C Simplify the expression:- :B-A
C
|
|
|
|
|
Programming
|
Learn how to optimize your programs, maintain efficiency, and even learn about some of the most sophisticated concepts in the world of programming.
|
|
|
|
|
Chess
|
Choose from these Chess topics:
|
|
|
|
|
Archives
|
Select a platform that you would like to download software for:
|
|
|
|
|