Compute!

Page 156

MACHINE LANGUAGE FOR BEGINNERS RICHARD MANSFIELD, SENIOR EDITOR

Safe Places This month we'll start constructing a game. It will be written entirely in machine language (ML). After each small section is written, we'll test it and combine it with other modules until the game is complete. Along the way, we'll learn the meaning of the commands available to us in ML, as well as how to build a program from start to finish. But first we've got to clear up an important

issue: where do you put an ML program? BASIC programs always start in the same address in the computer's memory. An unexpanded VIC starts

them at address 4096. VIC-20S with memory ex

sends control to the ML and RTS sends it back similar to the way you use GOSUB within BASIC. Also, when we use the Assembler, we're creating an ML program, but the Assembler itself is in BASIC — they've got to be in the computer at the same time. Where's the best place to put ML? On the 64, it's easy: you've got a block oi memory from 49152 lo 53247 (4096 cells, or 4K) which isn't disturbed by BASIC or the computer's operating system. We'll locate everything there from now on. On the VIC, it's a bit more tricky. For one

pansion start them at 4608. Commodore 64s start

thing, the Assembler itself would use up all the

them at 2048. ML programmers, however, must

available memory in an unexpanded VIC. And, when you add expansion memory to a VIC, several key memory locations shift around. For our pur poses, we'll assume that you've added at least 8K of expansion memory. We'll set aside a zone at the top of your memory expansion {from 12288 on) which will give us a good amount of protected space for our ML programs. Since BASIC uses up sume RAM memory to build its arrays and variables, we've got to protect our ML zone from being overwritten while BASIC is active. In fact, the Assembler builds an array. If you want to assemble something with it, you've

decide where they want to put their programs. When you fire up the Assembler (see last month's column), the first thing it wants to know is the starting address. The choice is yours. Nevertheless, there are some places you clearly can't put an ML program. ROM memory can't be POKEd or changed, so you can't store something there. Likewise, roughly the first 500

addresses are heavily used by the computer to keep track of the screen location of the cursor, current variable addresses, and many other things. The cassette buffer is safe enough (ad dresses 828-1019) if you use n disk drive. If you use cassettes, you will destroy what's in this buffer whenever you use the cassette drive. Another consideration is that you will often

got to protect the newly created ML program from

the Assembler itself. We can do this by fooling BASIC into thinking that its available RAM mem ory is less than it really is. This farces BASIC to

want to have an ML program and a BASIC pro

build its variables below the zone we set aside.

gram coexist inside the computer. For example,

This is done by POKEing location 56 with a 48. When you've done that, your computer will not disturb RAM memory above address 12287. To summarize, 64-users should always answer

many BASIC programs can be significantly speeded up by replacing slow sections, usually loops, with an ML program. SYS within BASIC 154

COMPUTES Gazelle

December 1983


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.