ebook img

128 machine language for beginners PDF

418 Pages·1986·33.92 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview 128 machine language for beginners

u u u u u Appendix C, "Commodore 128 MemoryMap/' wasoriginallypublishedin COM- PUTEl's 128Programmer's Guide, copyright 1985, COMPUTE! Publications, Inc. Copyright 1986, COMPUTE! Publications, Inc. Allrightsreserved. Reproduction ortranslation ofanypart ofthis work beyond thatpermittedby Sections 107and 108 ofthe United States CopyrightAct without the permission of the copyright owneris unlawful. Printedin the United States ofAmerica 10 987654321 u ISBN 0-87455-033-5 Theauthorandpublisherhavemadeeveryeffortinthepreparationofthisbooktoinsure theac- . . curacyoftheprogramsandinformation.However,theinformationandprogramsinthisbookare J [ soldwithoutwarranty,eitherexpressorimplied.NeithertheauthornorCOMPUTE!Publications, *—J Inc.,willbeliableforanydamagescausedorallegedtobecauseddirectly,indirectly,incidentally, orconsequentiallybytheprogramsorinformationinthisbook. Theopinionsexpressedinthisbookaresolelythoseoftheauthorandarenotnecessarilythoseof * I COMPUTE!Publications,Inc. COMPUTE! Publications, Inc., PostOffice Box5406, Greensboro, NC 27403, (919) •< j 275-9809, ispartofABC ConsumerMagazines, Inc., one oftheABC Publishing l J Companies, andisnotassociated with anymanufacturerofpersonal computers. Commodore 128 is a trademark ofCommodore ElectronicsLimited. -u Contents Preface v Introduction: Why Machine Language? ix 1 How to Use This Book 1 2 The Fundamentals 9 3 The Monitor 29 4 Addressing 51 5 Arithmetic 73 6 The Instruction Set 89 7 Borrowing from BASIC 127 8 Building a Program 137 9 ML Equivalents of BASIC Commands 155 10 The 128 Environment 189 11 Built-in Routines 199 Appendices 213 A 8502 Instruction Set 215 B How to Use LADS 247 C Commodore 128 Memory Map 267 D LADS Source Code 275 E Library of Subroutines 343 F Typing In LADS 349 G Commodore ASCII Codes 379 Index 389 Disk Coupon 393 H n n Preface n Few personal computers—indeed few computers of any kind— have been as thoughtfully designed or as attractive to people P"! who enjoy programming as the Commodore 128. It has sev eral environments, optimized disk access, 16 memory config urations, and dozens of special codes, escape sequences, and screen controls. It's a generously equipped toolbox for people who like to customize their computers and their software. And it offers the programmer a set of tools which are hitherto un matched in variety and power in a consumer computer. It represents the best of a breed: the eight-bit machine. These computers are built on chips which work with one byte at a time—the 8502 chip in the 128 and the 6502 chip upon which most of the first consumer computers were built. They are a technology in its twilight, but the 128 has significant strengths and could well survive for years as a model of what personal computers can be. The 68000 chip is emerging—Commodore's Amiga, Atari's ST, and Apple's Macintosh all use it—and no one can turn back the clock. This new 68000 is bigger, faster, and much more flexible than eight-bit chips. It can manipulate four bytes at a time and directly access massive amounts of memory. It doesn't need to switch banks, and it races along at eight times the speed of the older chips. It's the end of an age. Nevertheless, excellence can and often does appear at the end of an age. Bach, probably the finest musician ever, sum marized and synergized the music of his time. He embodied pi the best of what was then known. As it turned out, his sum maries and synergism have proven timeless and durable. There has been more dramatic music since, equal music per- (jmm\ haps, but no better music. The Commodore 128 is a complex, full, and rich summation of the best that is possible with an eight-bit machine architecture. It is a classic programmer's j—1 computer. You can spend years exploring its abilities. However, the heart of a computer is only accessible via machine language. Several years ago I decided to learn to pro- j""! gram in machine language, the computer's own language. I — understood BASIC fairly well and I realized that it was simply not possible to accomplish all that I wanted to do with my u u computer using BASIC alone. BASIC is sometimes just too slow. j / I faced the daunting (and exhilarating) prospect of learn- {—' ing to go below the surface of my computer, of finding out how to talk directly to a computer in its language, not the | f imitation English of BASIC. As I was to discover, something (—■> amazing lies beneath BASIC. Few events in learning to use a personal computer have \ ) had more impact on me than the moment that I could in- <—' stantly fill the TV screen with any picture I wanted because of a machine language program I had written. I was amazed at its speed, but more than that, I realized that anytime large amounts of information were needed onscreen in the future— it could be done via machine language. I had, in effect, created a new BASIC "command" which could be added to any of my programs. This command—using a SYS instruction to send the computer to my custom-designed machine language routine— allowed me to have previously impossible control over the computer. BASIC might be compared to a reliable, comfortable car. It will get you where you want to go. Machine language is like a sleek racing car—you get there with lots of time to spare. When programming involves large amounts of data, music, graphics, or games, speed can become the single most im portant factor. .After becoming accustomed to machine language, I de cided to write an arcade game entirely without benefit of BASIC. It was to be in machine language from start to finish. I predicted that it would take about 20 to 30 hours. It was a space invaders game with mother ships, rows of aliens, sound ... the works. It took closer to 80 hours, but I am probably more proud of that program than of any other I've written. , > After I'd finished it, I realized that the next games would —I be easier and could be programmed more quickly. The mod ules handling scoring, sound, screen framing, delay, and ^ » player/enemy shapes were all written. I only had to write < / new sound effects, change details about the scoring, create new shapes. The essential routines were, for the most part, al- ^ * ready written for a variety of new arcade-type games. When 1 i creating machine language programs, you build up a collection of reusable subroutines. For example, once you find out how ^ > to make sounds on your 128, you change the details, but not i 1 the underlying procedures, for any new songs. u VI n I \ The great majority of books about machine language as sume a considerable familiarity with both the details of microprocessor chips and with programming technique. This book assumes only a working knowledge of BASIC. It was de- signed to speak directly to the amateur programmer, the part- time computerist. It should help you make the transition from BASIC to machine language with relative ease. You'll quickly discover that machine language is your key to the excellence and power waiting within Commodore's 128. M you^tefer to purchase a disk coirttaTOrig the4pp§ cx^enieirt eoup#i m lie bacJtor tat loi n Vll

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.