Commodore BASIC: Difference between revisions

Content deleted Content added
Technical details: Abbreviating keywords did not affect the storage of programs in memory
Line 13:
Like the original [[Microsoft BASIC]] [[interpreter (programming)|interpreter]], on which it is based, Commodore BASIC is slower than native [[machine code]]. Test results have shown that copying 16 [[kilobytes]] from [[read-only memory|ROM]] to [[random-access memory|RAM]] takes less than a second in machine code, but over a minute in BASIC. To alleviate the slowness of the interpreter, programmers started using various techniques to speed up execution. One was to store often-used integer values in variables rather than using literal values, as interpreting a variable name was faster than interpreting a literal number. Programmers also often wrote speed-critical sections of a program in [[MOS Technology 6502|6502]] assembly language and executed them from BASIC using the <code>SYS</code> command.
 
Commodore BASIC [[keyword (computer programming)|keyword]]s could be abbreviated (tokenized) by entering first an unshifted keypress, and then a shifted version of the next keypress. These two characters were then parsed according to a lookup table, and accepted as a substitute for typing the entire command out. However, as BASIC keywords were stored in memory as single byte tokens, this was an convenience for statement entry rather than an optimization.
 
In the default [[graphic mode]], shifted characters appear as a graphics symbol; e.g. the command, <code>GOTO</code>, could be abbreviated <code>G{Shift-O}</code> (which resembled <code>G'''&Gamma;'''</code> onscreen). Most such commands were two letters long, but in some cases they were longer. In cases like this, there was an ambiguity, so more unshifted letters of the command were needed, such as <code>GO{Shift-S}</code> (<code>GO&hearts;</code>) being required for <code>[[GOSUB]]</code>. Some commands had no abbreviated form, either due to brevity or ambiguity with other commands. For example, the command, <code>INPUT</code> had no abbreviation because its spelling collided with the separate <code>INPUT#</code> keyword, which was located nearer to the beginning of the keyword [[lookup table]].