Saving Memory in TI-BASIC Programs A list of ways to cut down on program size By Francis Huang This text assumes basic knowledge of TI-BASIC. If you want to learn BASIC, download Winlink (www.education.ti.com/) and study the source code of some programs, consulting the Guidebook's index whenever something is confusing. By study, I mean typing it into the calculator by hand and learning where all the menu options are. It's fun! Contents: 1. Readability 2. Use of Subprograms 3. Speed up Division by Multiplying 4. Comparisons of not equal to 0 5. Use of Ans Topics specific to the TI-82/83(+): 6. Quotes and parentheses 7. Tricks with parentheses Conclusion 1- Readability Change all : (colons) that are not inside " " to carrige return since they are hard to read. This will take up the same amount of memory and may even help in taking off end quotes and parentheses when saving space. Before: Pause :Lbl 10:ClrDraw AxesOff:ClrHome:FnOff :Disp "TURN:" After: Pause Lbl 10 ClrDraw AxesOff ClrHome FnOff Disp "TURN:" 2- Use of Subprograms Combine an external subprogram into a single file if it is only called once. For example, if my main program calls prgmINIT only once, just copy the code from prgmINIT and paste it in place of the program call. Conversely, separate a function if it will be called many times. This will save memory, but slow down the calculator by a small amount. 3- Speed up Division by Multiplying - Multiply instead of divide when convenient. This results in a slight speed gain, though not so if the division involves fewer characters than the operation written out as a multiplication. Dividing by two usually works: e.g. (X+1)/2 becomes .5(X+1) - Dividing by 5, 10, 100, and other numbers whose inverse (1/X) have few digits can also be written using multiplication: X/5 becomes .2X X/10 becomes .1X The same goes with X/50, X/100, etc. 4- Comparisons of not equal to 0 In an If, While, or Repeat statement, there is no need to compare any variable, such as X, to 0 in the operation X!=0 (X not equal to 0). - Example: Instead of If A=1 or (X!=0) use If A=1 or X 5- Use of Ans Save temporary calculations in Ans if possible. To do this, put the calculation in a line all by itself, then it will automatically be stored into Ans saving the need for /->/(some variable). Before: If 8>C Then Pxl-On(X+H,Y+O+1) Else Pxl-Off(X+H,Y+O+1) End After: Y+O+1 If 8>C Then Pxl-On(X+H,Ans) Else Pxl-Off(X+H,Ans) End For TI-82/83(+) Only: 6- Quotes and parentheses Remove all dangling ) and " to save a byte This is sometimes the reason for using a carrige return instead of : (colon) to denote a new statement. For example: Disp "PRESS ENTER":Pause becomes: Disp "PRESS ENTER Pause which can further become, on the TI-83(+), Pause "PRESS ENTER Also, another example. 6H/->/[I](I,5) becomes: 6H/->/[I](I,5 The same applies with quotes and parentheses before the /->/ operation. Instead of X(L1(3)+1)/->/X I can use X(1+L1(3/->/X 7- Tricks with parentheses In comparing something equal to 0, use not(X). Then, remove the trailing ). This saves a byte. Example. If X=0 becomes: If not(X Comparisons can sometimes be rearranged to have their parentheses at the end, resulting in the ability to leave them out. Example. If L1(1)L1(1 Avoid extra parentheses, such as in the example If (A=1 and B=2) or (A=2 and B=1) Change to: If A=1 and B=2 or A=2 and B=1 Since the 'and' operator is higher precedence (evaluated first), there is no need for parentheses in this case. In other cases, as in If (P>0 and T=-1) or (P<0 and T=1) the parentheses may be necessary. Conclusion ========== Well, I hope this document reduces the amount of BASIC programs' size, and keeps more memory open so the calculator's memory does not overflow when loaded down with calculations. If you want to send me your comments, e-mail me at