home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / program / books / 68k_book / arp_doc / chap_01.doc < prev    next >
Text File  |  1985-11-20  |  39KB  |  728 lines

  1.      Atari ST Machine Specific Programming In Assembly
  2.  
  3. Chapter 1: Scope and Concepts
  4.  
  5.  
  6.      Beating the Atari ST Into Submission was my first title 
  7. for this book.  In order to conduct research in a field of 
  8. interest, I had assembled a computer system that I had 
  9. judged to be adequate; I had gathered all of the reference 
  10. material that I could find for that system; and I had 
  11. purchased software which, had the reference materials been 
  12. completely competent, should have permitted me to write the 
  13. programs I needed.
  14.      But, when I turned to the references for assistance in 
  15. designing my programs, I soon judged them to be inadequate 
  16. because of documentary errors and information omissions.  
  17. Eventually, I had to acknowledge the necessity of becoming 
  18. my own ST authority; I would have to write my own reference 
  19. book before I could write my software.  To accumulate the 
  20. knowledge required to write that book, I had to perform a 
  21. personal study of the ST.
  22.      This is my journal of that study, marked, not by 
  23. chronologically connected events, but by algorithmic 
  24. complexity, in the form of a series of programs which I 
  25. designed to gather experimental data about the hardware and 
  26. the operating system of the Atari 1040ST.  Using the 
  27. available reference material as a guide, I began to write 
  28. programs to test and expand the information contained in the 
  29. references.  As results were accumulated from the execution 
  30. of those programs, I began to write the book.
  31.      As I plodded along, day by day, I learned enough about 
  32. the ST to convince me that I should change the book's title; 
  33. because I discovered that the computer is not an unwilling 
  34. servant.  In fact, it is the machine's propensity to 
  35. obedience that has caused me to become so fond of it.
  36.      Yet, in the literature that I have seen, programmers 
  37. complain about system software defects, its limitations, its 
  38. inadequate documentation and its sluggishness; users 
  39. register identical complaints about application software.  
  40. My own experiences validate all of these complaints.  
  41. However, in spite of that validation, and in spite of the 
  42. construction and placement of its obscenity connectors, for 
  43. my needs, the Atari ST is the most capable personal computer 
  44. available.
  45.      It's not that the machine can't do, it's the way in 
  46. which it has been told to perform that prevents it, without 
  47. sufficient augmentation, from meeting my expectations.  I am 
  48. now convinced that all software produced for the ST can be, 
  49. and should be, as efficient, or better, than that of the 
  50. finest available for any other personal computer.  As 
  51. examples of the exceptionally fine software that can be 
  52. written for the ST, I need only point to the programs 
  53. TEMPUS, an editor; TURBO ST, an accelerator; Universal Item 
  54. Selector II, a replacement for the GEM item selector; and 
  55. MultiDesk, a desk accessory expander.  These excellent 
  56. programs are models of efficiency and utility because their 
  57. authors viewed and contemplated the ST as a unique 
  58. instrument, writing algorithms that are machine and 
  59. operating system specific to varying, appropriate degrees.
  60.      Most of the software that I have purchased for the ST 
  61. fails to satisfy my expectations because it does not perform 
  62. at my standards of speed and reliability levels, while 
  63. consuming minimum requisite memory.  These are the 
  64. attributes that I demand of the software I write.  Should I 
  65. expect less from the software I buy?  Some of the software 
  66. that I have purchased has failed to meet my expectations 
  67. because it has been reworked versions of programs initially 
  68. prepared for other machines; some has failed because it is 
  69. meant to be compatible with later versions of the ST or of 
  70. its operating system; a lot of it has failed because it is 
  71. just plain rotten.
  72.      I want programs that work correctly and efficiently on 
  73. the machine which I own.  I do not want bastardized versions 
  74. of programs that are hampered by the structure of the 
  75. machines for which the original versions of the software was 
  76. written.  Furthermore, I don't want to finance, by way of 
  77. time, money and space, the compatibility of currently 
  78. produced software with future Atari machines and/or 
  79. operating systems, which may or may not materialize.
  80.      In fact, I think that the software compatibility 
  81. between machines and operating systems issue is dead.  
  82. However viable it may have once seemed, I know only of the 
  83. hard work this concept has generated for programmers and the 
  84. inefficient programs that have been produced, in spite of 
  85. that hard work.  I am convinced that the proliferation of 
  86. computers and their operating systems has surpassed the 
  87. ability of programmers to maintain total compatibility.  
  88. Anything less than total compatibility is incompatibility, 
  89. by definition.
  90.      Personally, I don't care if my software is compatible 
  91. with any machine other than my own.  Furthermore, I don't 
  92. think it impertinent of me to suggest that consumers should 
  93. have learned by now that product satisfaction is relevant at 
  94. the time of purchase.  This applies to hardware or attendant 
  95. software.  My experience has proven to me that, for any 
  96. product purchased, there is no reason to expect that any 
  97. product enhancement will take place in the future, nor is 
  98. there any reason to expect that any enhancement which does 
  99. take place in one area will not be accompanied by 
  100. performance degradation in other areas.
  101.      Therefore, I have decided that, when using any 
  102. programming language, I want to be able to produce programs 
  103. that are as machine specific as possible because I want to 
  104. utilize programs that are as efficient in speed and size as 
  105. possible, whenever the task to be done warrants the 
  106. consideration.  I made a choice when I purchased my 
  107. computer; I made that choice based on the machine's hardware 
  108. and software as it existed at the time of purchase.  I chose 
  109. the Atari ST because I judged it to be the best, after 
  110. comparing it to all other personal computers available.
  111.      Choosing the ST is what we have in common, you and I; 
  112. and I can assume that you also have decided to explore the 
  113. issue of writing software, otherwise you would not be 
  114. indulging me this far.  I cannot assume anything about your 
  115. experience and notions concerning the subject, but, if you 
  116. are able to read this book, I can assure you that you can 
  117. write software for the ST.  Your ability is not the 
  118. question; you need only decide to invest the time required 
  119. to become acquainted with the tools of the trade.  But, 
  120. knowing how to use the tools will not make you want to be a 
  121. programmer; the decision concerning that desire is a 
  122. separate, personal issue.
  123.  
  124. Decisions
  125.   
  126.      When I was younger, I had decided that I wanted to be a 
  127. doctor.  After studying premed for three years, I realized 
  128. that I really did not relish the thought of the intimate 
  129. involvement with people, on a daily basis, which the 
  130. profession demanded.  I decided that I would rather work 
  131. with machines and instruments instead.  Therefore, I became 
  132. an engineer.
  133.      Your decision to be, or not to be, a programmer is 
  134. probably not as critical as the choice I had to make because 
  135. it need not involve daily employment.  You might view your 
  136. capacity to write computer programs as an enhancement to 
  137. your professional or personal life.  But, whether you decide 
  138. to program part time or full time, you should realize that 
  139. programming is work.  That's why we must pay for programs 
  140. written by others.
  141.      I find the work involved in computer programming to be 
  142. emotionally stimulating.  Perhaps it is the challenge of 
  143. achieving algorithmic perfection which excites me.  In 
  144. reaching for such perfection, I spend a significant amount 
  145. of time exploring the capacity of my computer.  I have 
  146. learned to regard these explorations as pleasant interludes 
  147. between frenzied programming sessions.
  148.      If you can adopt this attitude concerning your own 
  149. programming efforts, then the significance of the material 
  150. that I present in this book will be enhanced, because, here, 
  151. we enter regions of algorithmic activity that is only 
  152. scantily documented in the references.  Compounding the 
  153. inconvenience of sparse documentation are errors therein.  
  154. Nevertheless, I will certainly recommend references, but I 
  155. warn you that the bulk of it contains unconfirmed 
  156. assertions.  Of course, I will not be able to use such 
  157. material to support my own assertions.  Instead, in 
  158. conjunction with that which is available, I will have to 
  159. rely on the experimental results which have been produced by 
  160. the programs that I have used to explore the ST's 
  161. capabilities.
  162.      I encourage you to share the task of verifying the 
  163. accuracy and reliability of the evidence which I generate.  
  164. I will provide algorithms and explanations which seem 
  165. reasonable, based on what I assume to be prevalently 
  166. understood about the system's hardware and software; then I 
  167. will attempt to verify or disprove my suppositions, which 
  168. may, or which may not, be congruous with what is in print.  
  169. To you, I leave the responsibility of questioning my 
  170. activity to the extent that you will be cautious in the 
  171. application of my algorithms.
  172.      I expect my computer to do things blazingly fast.  When 
  173. my computer is executing a program, I want to see fire and 
  174. smoke.  I want my computer to kick ass.  When executing a 
  175. properly written, machine specific assembly language 
  176. program, the Atari ST does just that.  Furthermore, I 
  177. believe that this type of software can be produced by any ST 
  178. owner.
  179.      I feel that it is time for every owner to seriously 
  180. consider the benefits of tailor made programs.  Doing it 
  181. yourself is one way to guarantee that the software you use 
  182. performs accurately and reliably, at maximum possible speed, 
  183. while consuming only the requisite amount of memory.
  184.      I think that the most compelling issue, when deciding 
  185. whether to buy or write programs, is the degree to which the 
  186. computer user expects satisfactory performance from the 
  187. machine.  I do not even include the ability to program a 
  188. computer in the arbitrary list of factors which must be 
  189. considered.  Among those factors, however, I do wish to 
  190. include the disadvantage of indiscriminately relinquishing 
  191. control of machine performance to the producers of 
  192. commercial software.
  193.      Anyone that uses computer programs finds themselves in 
  194. the position of telling the computer to do things.  That's 
  195. all computer programming is; telling the computer to do 
  196. something.  The choice of levels at which the computer is 
  197. told to accomplish its tasks can be decided, as is proper, 
  198. by the ST user.  This choice is not always available to 
  199. users of other computers.
  200.      In addition to its compatibility with higher level 
  201. languages, the MC68000 microprocessor, by which the machine 
  202. is driven, facilitates the production of an assembly 
  203. language programming environment that is not much more 
  204. intricate than that of the higher level languages.  Also, 
  205. even though the ST's operating system is not as efficient as 
  206. it could (and should) be, its structure permits access that 
  207. enables a programmer to bypass it altogether or to augment 
  208. its more mundane routines.
  209.      It is true that, in the past, programming was a much 
  210. more difficult chore than it is today.  But the languages 
  211. and translators available now permit everyone to become 
  212. intimately involved with the generation of programs that 
  213. operate at maximum efficiency because they apply to specific 
  214. problems that are to be solved on specific machines.  After 
  215. all, we purchase personal computers because it permits us to 
  216. wield their power personally, so why should we not generate 
  217. personal programs that permit the maximum utility of that 
  218. power.
  219.      The amount of utility that one can realize from a 
  220. computer system is proportional to the amount of effort that 
  221. one is willing to invest in becoming intimate with its 
  222. hardware, its operating system and a means of communicating 
  223. with both.  The more knowledge a user is willing to 
  224. accumulate about these three subjects, the more productive 
  225. will be the intimate involvement.
  226.      That's what this book is about; obtaining and using 
  227. knowledge about the Atari ST; and using that knowledge to 
  228. write programs for it.  Programs that exploit the ST's 
  229. machine specific hardware, language and operating system.  
  230. To take advantage of the ST's powerful hardware and 
  231. software, you need not write long and intricate programs.  
  232. It is possible to wield a great deal of power simply by 
  233. writing smaller utilities and by being able to alter or 
  234. control purchased programs which do not meet your 
  235. performance expectations.
  236.  
  237. The Scope of the Book
  238.   
  239.      Book titles aside, I intend to place various types of 
  240. whips at your disposal; do with them what you will.   I will 
  241. not begin at the beginning.  Too many other authors have 
  242. already done that.  Instead, I shall begin in the middle, 
  243. point out the sources that have provided a beginning, and 
  244. try to show you a path to the end.  However, I will discuss, 
  245. in depth, those aspects of programming the MC68000 and the 
  246. ST which I feel have not been adequately presented 
  247. elsewhere.
  248.      Although I will discuss some of the basics of 
  249. programming, and although the programming medium I shall be 
  250. using in the book is assembly language, I will not be trying 
  251. to teach you the basics of assembly language programming, so 
  252. I'll describe sources for suitable material.  Concerning 
  253. programming in assembly language on the ST specifically, I 
  254. can say without hesitation that there are not enough books 
  255. available,  but there is sufficient elementary material 
  256. available concerning the individual subjects: programming in 
  257. assembly language and programming on the ST.
  258.      I am fond of assembly language programming because it 
  259. keeps one in touch with the capabilities of the processor.  
  260. Machine specific programming keeps one in touch with the 
  261. capabilities of the other hardware also.  Of course, 
  262. familiarity with the processor's language can be avoided, 
  263. even while one is "programming in assembly".  The advantages 
  264. of assembly language programming is circumvented by 
  265. programmers who rely solely on large libraries of routines 
  266. which are simply plugged into new programs.  Nevertheless, 
  267. the assembler that I will recommend does provide such 
  268. libraries.
  269.      I am against this practice because canned subroutines 
  270. keep you too far away from the intricacies of the processor 
  271. instructions.  It hinders the generation of new ideas about 
  272. algorithms.  Furthermore, it does not promote the 
  273. memorization of individual commands and patterns of command 
  274. groups.  I do advocate, however, the development of proven 
  275. routines that can be copied from one program to another.  It 
  276. is the concatenating of unreviewed blocks of source or 
  277. assembled code to new programs to which I object.
  278.      In general, the reference books for the MC68000 and the 
  279. Atari ST are very useful.  There are problems with some, but 
  280. none are totally devoid of redeeming qualities.  Some 
  281. portions of these books contain critical errors; other 
  282. portions completely neglect discussions of pertinent 
  283. functions; in my opinion, none of the books present example 
  284. programs in a progressively coherent fashion.
  285.      My desire, therefore, is to present material which does 
  286. not duplicate that which is already available and to offer 
  287. precise examples, beginning with the rudimentary, 
  288. progressing to the intricate, that are constructed in a 
  289. series of cohesive steps.  At each phase, algorithms will be 
  290. used that I have personally developed and tested.  These 
  291. algorithms will have been developed while using the 
  292. reference books to be mentioned.  You will be able to verify 
  293. my results, and you will be able to supplement information 
  294. in your references with my annotations.
  295.      I cannot write a book that incorporates details for 
  296. manipulating the entire ST operating system and all of the 
  297. computer's hardware.  I have restricted my interest to 
  298. selected portions of the Centronics interface, the DMA 
  299. interface, the video interface, the interrupt structure and 
  300. the operating system.  I will get as close to the hardware 
  301. as seems reasonable.  In some cases, this means I shall be 
  302. programming the hardware directly; in others, it means that 
  303. I shall get closer to it than is usual when using the 
  304. operating system, but not close enough to dissolve the 
  305. advantages of having the operating system in the first 
  306. place.
  307.      I will discuss desk accesssories, terminate and stay 
  308. resident programs (I prefer the term load and stay 
  309. resident.), custom trap installation, the power of self-
  310. modifying code, switching between screens, the file 
  311. selector, the initialization of applications, resource files 
  312. and subjects related to these areas of interest.  In 
  313. addition, I will discuss the use of the AssemPro assembly 
  314. language programming system and TEMPUS, a programmer's 
  315. editor, filling in some details not provided in their 
  316. documentation.  I will also clarify the differences between 
  317. programs that are assembled in each of AssemPro's three 
  318. assembly modes: PC-relative, Relocatable and Absolute.
  319.      Because the programs which I use require the higher 
  320. resolution of a monochrome monitor, I do not use a color 
  321. monitor.  Therefore, my examples do not include color 
  322. monitor specific code.  However, most of what I discuss is 
  323. monitor independent.  Besides, I think you will find that 
  324. the references provide adequate color monitor information.
  325.  
  326. The Attributes of Acceptable Software
  327.  
  328.      The programming concepts associated with computers have 
  329. always been dictated by machine hardware.  Over time, the 
  330. concepts of at least some critical portion of programmer 
  331. population have always kept pace with hardware development; 
  332. but not everyone has been amenable to the required shifts in 
  333. philosophy.  At times, some programmers have run amuck.
  334.      Four software attributes have always been desirable: 
  335. accuracy, reliability, speed and minimum memory requirement.  
  336. At times, the attributes speed and minimum memory 
  337. requirement have vied to be the more prominent 
  338. consideration.  Then, the fast processor, large memory 
  339. computer came along.  Suddenly, programmers were talking 
  340. about structured programming and across the board 
  341. compatibility.  Many programmers declared that speed and 
  342. memory requirements were passé considerations.  Some of them 
  343. even threw out the accuracy and reliability attributes for 
  344. good measure.
  345.      Then, Kernighan and Ritchie wrote the bible.  In the 
  346. beginning there were complaints to be heard from the masses.  
  347. Eventually, many programmers began to learn how to use the 
  348. language that was faster than fast and somewhat relaxed in 
  349. its requirements for structure.  But one group of 
  350. programmers insisted that, although C was faster than other 
  351. high level languages, it was still not faster than fast; 
  352. only assembly language could achieve such distinction.  
  353. Furthermore, they declared that C had a voracious appetite, 
  354. gobbling up memory like a pac-man.
  355.      But it was much easier to program in C than it was to 
  356. program in assembly, so many were converted.  The MC68000 
  357. driven Atari ST coupled with the AssemPro assembly language 
  358. programming environment has nullified that advantage.  Using 
  359. AssemPro, programming in assembly on the Atari ST is as 
  360. convenient as programming in C.  And now that the editor 
  361. TEMPUS is available, the task is even easier than it had 
  362. been.
  363.  
  364. The Concepts Which Shape the Book
  365.   
  366.      What programming concepts must be accepted in order 
  367. that maximum utility be achieved with the Atari ST?  Machine 
  368. specific programming in assembly is the first.  The reason I 
  369. insist that this concept be acceptable is that it permits 
  370. both the speed and minimum memory requirement attributes to 
  371. be incorporated into program design simultaneously.  There 
  372. are other advantages to assembly language programming; I 
  373. believe that they will become apparent as we go along.
  374.      Compatibility and portability as desirable program 
  375. attributes must be dismissed.  Programs that are designed 
  376. with emphasis on these criteria are inherently inefficient; 
  377. there are too many machines and too many differences between 
  378. them.  User satisfaction should supplant those criteria.  
  379. Embodied in the concept of user satisfaction are the 
  380. accuracy and reliability attributes.
  381.      I know that some people think that a megabyte of memory 
  382. is takusan.  Just remember that there was a time when they 
  383. thought that 64 kilobytes was a lot.  About memory, I say 
  384. that you can't have too much.  The basic law of applications 
  385. is that they will expand to fill all corners of available 
  386. memory, whether they are heated or not.  About speed, I say 
  387. this: if you're not in a hurry, do it by hand and give your 
  388. computer a rest.  If you are going to use a computer then 
  389. you should always be concerned about accuracy, reliability, 
  390. speed and memory requirements.
  391.      Don't be fooled by those who offer you inferior 
  392. programs, declaring that one or more of these software 
  393. attributes are no longer relevant.  As a user, it is your 
  394. right to demand that all software you purchase meets these 
  395. criteria.  Actually, I believe that Atari ST users have 
  396. already begun to rebel.  Of course, some software producers 
  397. find it hard to believe that we are intelligent enough to 
  398. decide what it is that we want; they prefer to believe that 
  399. users are giving copies to each other.  Hah!  Most of the 
  400. software that I have purchased has gone straight to the 
  401. trash can because I could not use it myself.
  402.      In presenting my material, I shall use a concept that I 
  403. call the minimum code necessary; this means that I will 
  404. introduce routines, my own and those of the operating 
  405. system, with the minimum amount of code necessary to 
  406. illustrate the use of each routine.  Therefore, you will be 
  407. able to see what is actually required by an algorithm versus 
  408. that which some of the reference books indicate.  I shall 
  409. compare certain algorithms that have become "standard" in ST 
  410. literature to ones that accomplish identical goals easier, 
  411. faster, and with less memory requirements.
  412.  
  413. Reference Material
  414.   
  415.      I will now list the reference materials which I 
  416. consider to be the best available.  At least some of these 
  417. books are indispensable.  I suggest that you look at all of 
  418. them and purchase those you find affordable; all are 
  419. desirable.  I will indicate those which I feel that I can 
  420. recommend without reservation, but which you might not be 
  421. able to locate; you may decide to order them through a local 
  422. bookstore.
  423.  
  424.      1. Ford, W. and Topp, W., The MC68000 Assembly         
  425.         Language and Systems Programming, D.C. Heath 
  426.         and Company, 1988.  This book contains material for 
  427.         both beginning and advanced college semesters.  It 
  428.         is the most comprehensive MC68000 book available.
  429.  
  430.      2. Erskine, R., First Steps in Assembly Language for 
  431.         the 68000, Bantam Books, Inc., December 1986.  An 
  432.         excellent beginner's book.
  433.  
  434.      3. Skinner, T.P., Assembly Language Programming for the 
  435.         68000 Family, John Wiley & Sons, Inc., 1988.
  436.  
  437.      4. Kelly-Bootle, S., 680x0 Programming by Example, 
  438.         Howard W. Sams & Company, 1988.  This book offers 
  439.         more detail, especially about the addressing modes, 
  440.         than a mere beginner's book.  I strongly recommend 
  441.         this book.  The author rates his book as elementary 
  442.         to intermediate.  I rate it as elementary+ to 
  443.         intermediate+.  I purchased this book while I was 
  444.         writing the fifth chapter of mine; I'm sorry that 
  445.         his was not available sooner.  It is good reading.
  446.  
  447.      5. Peel, K.D., Concise Atari 68000 Programmer's 
  448.         Reference Guide, Glentop Publishers Ltd, 1986.  An 
  449.         excellent book.  It discusses the entire Atari ST 
  450.         operating system.  It is, however, somewhat cryptic 
  451.         for beginners.  The address of the publisher 
  452.         is: Glentop Publishers Ltd, Standfast House, Bath 
  453.         Place, High Street Barnet, Herts EN5 5XE. Tel: 01-
  454.         441-4130
  455.  
  456.      6. Gerits, K., Englisch, L. and Bruckmann, R.,
  457.         Atari ST Internals, A Data Becker Book, 
  458.         published by Abacus Software.  You must have 
  459.         this book; the 3rd revision, or later if 
  460.         possible.
  461.  
  462.      7. Leemon, S., Atari ST Volume One: VDI, Compute!  
  463.         Publications, Inc., 1987.  This book relies mostly 
  464.         on the C language, however, it does contain 
  465.         pertinent pertinent reference material.
  466.  
  467.      8. Leemon, S., Atari ST Volume Two: AES, Compute! 
  468.         Publications, Inc., 1987.  There is more assembly 
  469.         language in this book than there is in the VDI book.  
  470.         If I could afford to purchase only one of the Leemon 
  471.         books, I would choose this one.
  472.  
  473.      9. Szczepanowski, N. and Gunther, B., Atari ST GEM, A 
  474.         Data Becker Book, published by Abacus Software., 
  475.         1985.
  476.  
  477.      NOTE: You should have either item 9 or items 7 and 8.  
  478.            Personally, I have found the COMPUTE! books and 
  479.            the Abacus book to be valuable.
  480.  
  481.     10. Pollack, L. and Weber, E., Atari ST Application 
  482.         Programming, Datatech Publications, 1987.  No 
  483.         assembly language here, only C.  But this book is my 
  484.         favorite source for information about GEM when I 
  485.         program in C, so I had to mention it.
  486.  
  487.     11. Motorola, M68000 Programmer's Reference Manual, 5th 
  488.         edition or later, Prentice-Hall.
  489.  
  490. Software Needed
  491.   
  492.      You must have an assembler, an editor and a debugger.  
  493. Most assembly language packages contain all three software 
  494. tools.  AssemPro is such a package and is, beyond question, 
  495. the most convenient, feature ridden assembly language 
  496. package that is available for the Atari ST.  The assembler 
  497. may not produce code as fast as some, and the response of 
  498. the editor is not as quick as I would like, but the debugger 
  499. is superb.  I suggest that you use TEMPUS as your primary 
  500. editor, resorting to the AssemPro editor for minor 
  501. corrections while attempting to assemble.
  502.      The possession of these two tools, AssemPro and TEMPUS, 
  503. will put you in the most advantageous position possible for 
  504. writing assembly language programs, or for altering existing 
  505. programs to suit your preferences.  If you already have an 
  506. assembler, you might try to get along with it.  Or a newer 
  507. assembler might become available before this book does.  In 
  508. that case you may decide to try the newer one.  In any case, 
  509. good assemblers are not expensive.  Neither is TEMPUS 
  510. expensive.
  511.  
  512. Telling The Computer To Do Things
  513.   
  514.      Because the phrase "telling the computer to do things" 
  515. is awkward to use, and because it takes up so much room on a 
  516. page, I suppose that the conversion to the word 
  517. "programming" was inevitable.  But it is worth remembering, 
  518. from time to time, that the word programming means just 
  519. that.  If one uses a computer at all, one is involved in 
  520. programming.  Am I trying to make it all seem much easier 
  521. than it is?  Nope.  I'm just trying to get you to look at 
  522. the subject from a different perspective than that to which 
  523. you might be accustomed.
  524.      Various definitions are applied to the manner in which 
  525. we tell a computer to do things.  Input, statements, 
  526. algorithms, subprograms, subroutines, macros, code, 
  527. programs; it all means the same thing.  We can tell it to do 
  528. one thing and stop; we can tell it to do many things, one at 
  529. a time, as we intervene at each step; or we can prepare a 
  530. list of things for the computer to do, call that list a 
  531. program, and submit it as a bulk transaction to the computer 
  532. for execution.
  533.      In general, a program is composed of a sequential list 
  534. of statements, one or more of which may be perceived as 
  535. comprising a single task that we can arbitrarily label a 
  536. distinct algorithm.  If the statements which form such an 
  537. algorithm are grouped together in a module, separated from 
  538. the sequential list, and if that module is called upon to 
  539. perform its task by one of the sequential statements, then 
  540. we can arbitrarily label the algorithm a function, 
  541. subroutine or subprogram.  Since we can apply the word 
  542. algorithm to the steps required to accomplish any task, 
  543. regardless of the length of the algorithm, much of the above 
  544. jargon is superfluous.
  545.      We write a program, or algorithm, for our computer when 
  546. we want it to do something that it can do better than we, or 
  547. when we feel that what we want to accomplish is too tedious 
  548. and/or repetitious to warrant human intervention.  
  549. Programming is a difficult chore only to the extent that we 
  550. find it difficult to express the things that we want 
  551. accomplished, whether to another person or to a computer.  
  552. The ability to express oneself is developed with education 
  553. and experience, over a period of time.  There are short 
  554. cuts; primarily the short cuts are taken by using reference 
  555. material.  However, be aware that faulty reference material 
  556. can hinder your effort; therefore, be suspicious.  Take 
  557. nothing for granted; least of all; another person's 
  558. certainty.
  559.      I think that writers have finally realized that the 
  560. phrases must do and can't do just do not apply to the Atari 
  561. ST.  It seems that every other week or so someone is doing 
  562. something that had been a can't do, according to all 
  563. available reference material.  I shall certainly try to 
  564. avoid the terms myself; but if I do happen to use them 
  565. inadvertently, please remember what I have said in this 
  566. paragraph.
  567.      The key to success with reference material is to have 
  568. as many sources as possible, trust none of them, and verify 
  569. every item of information that involves your current task.  
  570. If a reference book indicates that you must include a 
  571. certain block of code in a program, verify the information 
  572. by leaving out the entire block, then, by leaving out 
  573. portions of it that seem redundant.  Much of what I say in 
  574. this book is designed to assist you in learning how to spot 
  575. and eliminate redundant and/or inefficient code.
  576.  
  577. The Programs in the Book
  578.   
  579.      I want the programs and algorithms that I present to 
  580. flow into my discussions naturally, to fill inquisitive gaps 
  581. opened by previous presentations, so that your learning will 
  582. not be as haphazard as was mine.  The plan that I developed 
  583. is as follows.  I shall begin with the simplest of programs.  
  584. That program initiates a debate concerning the various 
  585. methods of implementing a simple task.  Conclusions drawn 
  586. from the debate require verification.  Verification requires 
  587. the use of slightly more complex algorithms.  These 
  588. algorithms have universal application, but they also incite 
  589. debate, conclusions and verification.
  590.      In order to keep track of a sequence of related 
  591. algorithms as they appear, I have chosen to use a program 
  592. naming procedure as follows.  The programs that supplement a 
  593. current discussion form a set for which the name of each 
  594. program in the set shall have the format PRG_nxy, where n is 
  595. an integer that follows sequentially from the previous 
  596. program set; x is a letter of the alphabet, beginning with A 
  597. for the first program in a set, proceeding to B for the 
  598. second and so on; y is one of the letters A, P, R or C.  
  599. These letters indicate the assembly mode for which a source 
  600. file has been prepared and the assembly mode used to 
  601. generate the object file.
  602.      The letter A is used to designate a source code file 
  603. that has been prepared specifically for assembly in 
  604. AssemPro's Absolute mode and to indicate that an object code 
  605. file has been assembled in that mode.  The letter P is used 
  606. for source code that is prepared specifically for assembly 
  607. in AssemPro's PC-relative mode and for the resultant object 
  608. code file.  The letter R is used for source code that is 
  609. prepared specifically for assembly in AssemPro's Relocatable 
  610. mode and for the resultant object code file.  The letter C 
  611. is used for source code that is prepared specifically for 
  612. assembly in the Combination mode and for the resultant 
  613. object code file.  I apply the term combination mode to 
  614. programs which use pc-relative addressing, but which are 
  615. assembled in the Relocatable mode.
  616.      The source code of all programs in the set shall have 
  617. the usual .S assembly language extension.  The assembled 
  618. programs shall have the appropriate .PRG, .TOS, .TTP, or 
  619. .ACC extension.  For some examples, object code with more 
  620. than one extension will be required.  Unrelated programs are 
  621. named according to their utility.  For example, a program 
  622. named SPEEDTST measures loading and execution times; a 
  623. program named LEA_ADDA compares the efficiency of the LEA 
  624. instruction to that of the ADDA instruction in a particular 
  625. application.
  626.  
  627. Program Documentation
  628.   
  629.      I am currently reading a brand new MC68000 assembly 
  630. language programming book.  The author of this book 
  631. discusses subjects for which I have had a deepening 
  632. interest.  I was shocked, however, to read his statements 
  633. concerning program documentation.  In essence, his 
  634. statements imply a belief that program documentation should 
  635. be held to the very minimum necessary.  He speaks of 
  636. documentation as if it contaminates the programs in which it 
  637. appears.  This type of thinking is definitely not current.
  638.      Storage mediums are inexpensive; time is not.  Trying 
  639. to understand sparsely documented code that you have already 
  640. written is probably much harder than writing new code.  It's 
  641. one of those Murphy's laws with which programmers become all 
  642. too familiar.  So take advantage of storage medium space to 
  643. save time.  Of course, when you are providing example code 
  644. for the perusal of others, all choice is preempted.  For 
  645. your own use, I suggest that you have at least two or three 
  646. fully documented copies of your algorithms in a safe place.  
  647. Then you can use them in programs undocumented, whenever you 
  648. choose to do so.
  649.  
  650. The Science of Programming
  651.   
  652.      As you probably know, there are those who prefer to 
  653. view the programming discipline as an esoteric art.  I 
  654. suppose that, to those with that perception, documentation 
  655. is as artistic as is programming.  However, I do not place 
  656. as much emphasis on the artistic nature of programming as do 
  657. others.  Programming is as much a discipline as is 
  658. engineering.  I know this to be true because I am both an 
  659. engineer (BSEE) and a programmer.
  660.      The list of instructions which comprise a computer 
  661. program must be precise.  The ability to issue instructions 
  662. precisely depends on knowledge, discipline and dedication to 
  663. the scientific method of investigation; it does not depend 
  664. on artistic talent.  Using the scientific method to prepare 
  665. a computer program that will produce accurate, verifiable 
  666. results, one proceeds, with specifications, from a situation 
  667. that is characterized by a desire to accomplish a task, to a 
  668. situation in which a tool that can be used to accomplish the 
  669. task has been assembled.
  670.      Unlike some, I believe that even an algorithm that 
  671. provides a correct solution can be unsatisfactory because it 
  672. is not the most time and memory efficient algorithm that can 
  673. be produced on the machine for which it is written.  I 
  674. believe that there is a set of most satisfactory algorithms 
  675. which can be written for every machine.  Any algorithm that 
  676. is not a constituent of that set is undesirable.
  677.      Yet there is a time and a place for undesirable 
  678. algorithms.  They are what you use while you are learning to 
  679. develop the set of most desirable algorithms.  Writing the 
  680. best possible algorithms for a machine can only be done by 
  681. programmers who are committed to a methodically study of the 
  682. machine's hardware and software, to scientific methods of 
  683. experimentation and to meticulous verification.  In 
  684. addition, it involves the most horrific task that can be 
  685. contemplated by the owner of expensive machinery; it 
  686. requires that one be very familiar the machine's 
  687. instructions and with references that support those 
  688. instructions.
  689.      I cannot promise to deliver a set of most satisfactory 
  690. algorithms for your particular needs, but I can show you how 
  691. I go about producing my own set.  I will show you the 
  692. deliberate care with which I choose each instruction of each 
  693. algorithm.  In developing the algorithms, whenever a choice 
  694. can be made from two or more instructions, and when I 
  695. conclude that the choice is not trivial, I will show you how 
  696. I evaluated the benefits of each, and I will tell you why I 
  697. chose that which I felt to be the most correct for the 
  698. application involved.  Likewise, when a choice is made from 
  699. two or more algorithms or programs, I will provide similar 
  700. information.
  701.      I promise to deliver reproducible results and 
  702. verifications.  But you must remember that the results were 
  703. obtained within my programming environment.  Furthermore, 
  704. when I direct your attention to flaws in the ST programming 
  705. environment, which includes the hardware, operating system 
  706. and purchased programs, remember that these flaws were 
  707. evident in my programming environment.  What you see in your 
  708. environment may not be identical to what I see in mine.  
  709. Therefore, you should use my results and observations as 
  710. indicators of what you might experience; but you should not 
  711. accept them as conclusive evidence of anything.
  712.  
  713. Conclusion
  714.   
  715.      In this chapter, I have tried to convince you that 
  716. writing machine specific programs is a viable alternative to 
  717. purchasing unsatisfactory software.  Further, I have 
  718. emphasized assembly language as the most efficient medium by 
  719. which this alternative can be exercised.  I believe that I 
  720. can show you how to dissolve the complexity of assembly 
  721. language programming by dividing each programming task into 
  722. manageable levels, wherein isolated subtasks are reduced to 
  723. trivia.  In the chapters ahead, I present my proof that you 
  724. can do the job.
  725.  
  726.  
  727.  
  728.