30.12.2013 Views

May June 1980 - Commodore Computers

May June 1980 - Commodore Computers

May June 1980 - Commodore Computers

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

MAY/JUNE, MAV/JUNE. <strong>1980</strong> , ISSUE 4, A COMPUTE. JJ 33<br />

VARIABLE NAMES AND CONSTANTS<br />

VARIABLE NAMES AND CONSTANTS<br />

As each new variablea blc is encountered, , it is assigned<br />

a number. These numbers begin with 128 and are<br />

a ss igned sequentia ll y u p to 255. Notice these numbers<br />

assigned sequentially up to 255. Notice these numbers<br />

will fit illlo into onc one byte. b Also, , ass each new variable<br />

is encounlered encountered, , the variable name m e is aadded d ded to LO a<br />

variable able name list, , aand 8 bytesb olr memory are reserved<br />

for ror that variable. In the case o[ of undimensioned<br />

ned<br />

variables, these 8 b ytes will co nta in the value o[<br />

variables, these 8 bytes will contain the value of<br />

the e variable. For r strings and arrays, , these 8 bytes<br />

will contain parameters, m e rs, wid1 with the actuall values and<br />

characters rs slOreci stored elsewhere.<br />

.<br />

This method elhod of oi handling n variables has somee<br />

advantages. tages, One advantage is thatt it keeps usage to a<br />

minimum. , The variable name is onlyy stored once, aand<br />

each time that name m e is referenced renced in a BASIC state tc­<br />

ment, , it occupies onlyy onee byte in thc the stored<br />

program. program, Another r advantage is thatt the address<br />

where the value forr a variable e is stored slO can be<br />

computed [rom from the assigned number. u m This isn't true<br />

of the BASIC found in somem e other microcomputersm m where values muSt must be searched [or. for.<br />

There are also some disadvantages as well, well. First,<br />

it limits its you to 128 different variable names. . How­<br />

ever, , the great majority of programsp m s won't ' t need more<br />

a rc<br />

tha n 128 variable na m es. O ne o th e r ci isacivaJ1l agc is<br />

than 128 variable names. One other disadvantage is<br />

that a t should a variablea name m e be no longer needed,<br />

or accidental)' ly entered due to a typo, there is no quick<br />

way to remove that variable from the variable name<br />

list and reuse the 8 bytes reserved forr it.<br />

Apparently, the only wayy lO to gel get rid off unwanted<br />

variablesa is to LIST the program m to cassen cassettee or<br />

disk. For example, LIST ""CC will lisl list the program<br />

to cassette. , Once the program is saved, , use the NEW<br />

command to clear the old program. Then useu the<br />

ENTER ER command to lO reload the ,he program. ra m . For<br />

cassette ll e this lh would be ENTER ""C. Using g the LIST<br />

command saves the program in character form. .<br />

ENTERingE the program m then lhen causes each line lO to be<br />

converted again as was done when n you first typed<br />

it in. . Now onlyy the variables found in the programp m<br />

will be pla ced in the vari a ble name list, a nd spa ce<br />

will be placed in the variable name list, and space<br />

reserved forr lhe their value. Using CSAVE aand CLOAD<br />

won't ' t do this because these save aand load a copy of<br />

the memory o where the program ram is stored. red, UnwantedU variables are rc saved aand loaded with (he the rest off<br />

the program. p .<br />

Constants nts are stored in the BASIC statements<br />

along with the restt or of the line. The constant will<br />

be proceeded precced ed by a ""14"' tokenn as mentionedm previously.<br />

Explaining how ATARI A R I BASIC: rc represents presc nls<br />

the numbers used lI ass constants nt s and as variable<br />

,'a values will require some explanation about BCD<br />

((Binary Coded Decimal) numbers. I will save this lhis<br />

information n for a later r article.<br />

e ,<br />

Too give aann example off using g the information<br />

n<br />

in this section, , let's t take a look at the variable<br />

name list. Ii Sl. Fortunately a lely bytes bYles 130 aand 1311 contain<br />

the address dress of the beginning off the variable e namem e<br />

list. st, The list will consist eonsist off a string off characters,<br />

each ch a racte r occupying o ne byte o r m e mory, T o<br />

each character occupying one byte of memory. To<br />

indicate the (he last character of a name, m ATARI<br />

BASIC addss 128 to lo the value representingg lha thatl<br />

character. Since the values representing ng the characc­<br />

te rs won' t exceed 127 , the new val ue will still<br />

ters won't exceed 127, the new value will still<br />

fit into one byte. b Too indicate ica the eend of the list, ,<br />

a 0 is placed in the byte following g the last<br />

character a off the last name. m e , The program m which<br />

prints the variable a e name list is given in Listing 4.<br />

.<br />

Notice whcn when you u run this program, m , thatt the "C' "("<br />

is saved ass part of a array y name, m e , and the "$"<br />

as pan of a stringg name.<br />

m e ,<br />

MEMORY ORGANIZATION<br />

Finally, let'ss look at how the memory m storage is<br />

organized lo forr a BASIC program. program, The order in which<br />

the various parts off a program m are found in<br />

memory is shown in Figure 1. 'The only part whose<br />

beginning is fixed is the variable namem e list which<br />

begins a t address 2048. T'he begin ning of the mhe r<br />

begins ai address 2048. The beginning of the other<br />

parts pans will move appropriately, pria ass the program m grows.<br />

There are addresses in page zero which can be used<br />

to iind find each off the lhe parts shown in Figure 1. These<br />

addresses, usually y called pointers, are shown in Table<br />

I, I. This table includes the two pointers which were<br />

used in the previousp s programs. p m Figure !:,» ,' End onlf Array Storage IOra,L:t: An:a Area<br />

",'n' Bl'.I.:ill Beginning ll ing off Array StorageS !Ura ,~'c An:a Area<br />

n F,' ' End of oi' Program<br />

ll1<br />

'nn' Bq.{i Beginning nilln g- off Program P rogT

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!