Use Less RAM By Typing More

Authors

Publication

Pub Details

Date

Pages

Don Lambert wrote me a letter and stated that being a less experienced programmer he could not understand why I used statements with VAL and CODE in them.

The answer, Don, is to save program space. Just a couple of bytes saved can sometimes save a whole disk track of 5090 bytes!

One of my favorite examples is Larry Kenny opening up channel 4 to access his LKDOS because PRINT #4 is easier to type [less key strokes] than RAND USR 100. [page 11 of his V3 manual] Also, he told me it takes up less RAM space in a program. Well, LARRY, it can USE UP MORE RAM space! The problem I have is channel 4 is also assigned to my ZEBRA Talker and I can’t change that.

Consider a short program to load LogiCall. Get in front of your machine and do the following:

Turn on your TS2068 and type PRINT FREE. You get 38652. This is our free RAM space. Now enter the two lines:

 10 RANDOMIZE USR 100: OPEN #4, "dd" 
20 PRINT #4: LOAD "L.B1"

Now type PRINT FREE <ENTER>. You get 38609. Strange, you just added 9 keystrokes to the program and gained 9 bytes of RAM!

Now EDIT the lines and put VAL with quotes around the 100 and the 4s. The program now reads:

 10 RANDOMIZE USR VAL"100": OPEN #4, "dd" 
20 PRINT # VAL"4": LOAD "L.B1"

Now type PRINT FREE . You get 38609. Strange, you just added 9 keystrokes to the program and gained 9 bytes of RAM!

Now lets try the ultimate RAM saving trick. Most numbers over 31 can be expressed in the program as CODE. Let’s change VAL”100″ to CODE”d” , do you follow me, Don? It is on page 242 in the TS2068 manual. The program now reads:

 10 RANDOMIZE USR CODE"d": OPEN # VAL "4" "dd"
20 PRINT # VAL"4": LOAD "L.B1"

Now type PRINT FREE . You get 38611. Losing the two zeros bought us two bytes. Notice that the following statements all mean the same thing.

RANDOMIZE USR 100 
RANDOMIZE USR VAL "100" RANDOMIZE USR CODE "d"

But what about OPENing channel 4 to save RAM space. Type in the program:

 10 LET h=CODE "d"
20 RANDOMIZE USR h: LOAD "L.B1"

Now type PRINT FREE. You get 38624.

Both programs will LOAD LogiCall but the channel 4 call uses 41 bytes while the USR call uses only 28. Also, for the record, RAND USR h is six bytes shorter than PRINT # 4 and just as easy to type,

Products

 

Media

 

Image Gallery

Source Code

Scroll to Top