1、单片机外文翻译汇编语言的艺术译文 英文实用资料The Art of Assembly Language1. Whats Wrong With Assembly Language?2. Whats Right With Assembly Language?1. Whats Wrong With Assembly LanguageAssembly language has a pretty bad reputation. The common impression about assembly languageprogrammers today is that they are all hacke
2、rs or misguided individuals who need enlightenment.Here are the reasons people give for not using assembly: (1)Assembly is hard to learn. (2)Assembly is hard to read and understand. (3)Assembly is hard to debug. (4)Assembly is hard to maintain. (5)Assembly is hard to write. (6)Assembly language prog
3、ramming is time consuming. (7)Improved compiler technology has eliminated the need for assembly language. (8)Today, machines are so fast that we no longer need to use assembly. (9)If you need more speed, you should use a better algorithm rather than switch to assembly language. (10)Machines have so
4、much memory today, saving space using assembly is not important. (11)Assembly language is not portable.These are some strong statements indeed!Given that this is a book which teaches assembly language programming, written for college level students, written by someone who appears to know what hes ta
5、lking about, your natural tendency is to believe something if it appears in print. Having just read the above, youre starting to assume that assembly must be pretty bad. And that, dear friend, is eighty percent of whats wrong with assembly language. That is, people develop some very strong misconcep
6、tions about assembly language based on what theyve heard from friends, instructors, articles, and books. Oh, assembly language is certainly not perfect. It does have many real faults. Those faults, however, are blown completely out of proportion by those unfamiliar with assembly language. The next t
7、ime someone starts preaching about the evils of assembly language, ask, how many years of assembly language programming experience do you have? Of course assembly is hard to understand if you dont know it. It is surprising how many people are willing to speak out against assembly language based only
8、 on conversations theyve had or articles theyve read.Assembly language users also use high level languages (HLLs); assemblys most outspoken opponents rarely use anything but HLLs. Who would you believe, an expert well versed in both types of programming languages or someone who has never taken the t
9、ime to learn assembly language and develop an honest opinion of its capabilities?In a conversation with someone, I would go to great lengths to address each of the above issues.Indeed, in a rough draft of this chapter I spent about ten pages explaining what is wrong with each of the above statements
10、. However, this book is long enough and I felt that very little was gainedby going on and on about these points. Nonetheless, a brief rebuttal to each of the above points is in order, if for no other reason than to keep you from thinking there isnt a decent defense for these statements.Assembly is h
11、ard to learn. So is any language you dont already know. Try learning (really learning) APL, Prolog, or Smalltalk sometime. Once you learn Pascal, learning another language like C, BASIC, FORTRAN, Modula-2, or Ada is fairly easy because these languages are quite similar to Pascal. On the other hand,
12、learning a dissimilar language like Prolog is not so simple.Assembly language is also quite different from Pascal. It will be a little harder to learn than one of the other Pascal-like languages. However, learning assembly isnt much more difficult than learning your first programming language.Assemb
13、ly is hard to read and understand. It sure is, if you dont know it. Most people who make this statement simply dont know assembly. Of course, its very easy to write impossible-to-read assembly language programs. Its also quite easy to write impossible-to-read C, Prolog, and APL programs. With experi
14、ence, you will find assembly as easy to read as other languages.Assembly is hard to debug. Same argument as above. If you dont have much experience debugging assembly language programs, its going to be hard to debug them. Remember what it was like finding bugs in your first Pascal (or other HLL) pro
15、grams? Anytime you learn a new programming language youll have problems debugging programs in that language until you gainexperience.Assembly is hard to maintain. C programs are hard to maintain. Indeed, programs are hard to maintain period. Inexperienced assembly language programmers tend to write
16、hard to maintain programs. Writing maintainable programs isnt a talent. Its a skill you develop through experience.Assembly language is hard. This statement actually has a ring of truth to it. For the longest time assembly language programmers wrote their programs completely from scratch, often re-i
17、nventing the wheel. HLL programmers, especially C, Ada, and Modula-2 programmers, have long enjoyed the benefits of a standard library package which solves many common programming problems. Assembly language programmers, on the other hand, have been known to rewrite an integer output routine every t
18、ime they need one. This book does not take that approach. Instead, it takes advantage of some work done at the University of California, Riverside: the UCR Standard Library for 80x86 Assembly Language Programmers. These subroutines simplify assembly language just as the C standard library aids C pro
19、grammers. The library source listings are available electronically via Internet and various other communication services as well as on acompanion diskette.Assembly language programming is time consuming. Software engineers estimate that developers spend only about thirty percent of their time coding
20、 a solution to a problem. Even if it took twice as much time to write a program in assembly versus some HLL, there would only be a fifteen percent difference in the total project completion time. In fact, good assembly language programmers do not need twice as much time to implement something in ass
21、embly language. It is true using a HLL will save some time; however, the savings is insufficient to counter the benefits of using assembly language.Improved compiler technology has eliminated the need for assembly language. This isnt true and probably never will be true. Optimizing compilers are get
22、ting better every day. However, assembly language programmers get better performance by writing their code differently than they would if they were using some HLL. If assembly language programmers wrote their programs in C and then translated them manually into assembly, a good C compiler would prod
23、uce equivalent, or even better, code. Those who make this claim about compiler technology are comparing theirhand-compiled code against that produced by a compiler. Compilers do a much better job of compiling than humans. Then again, youll never catch an assembly language programmer writing C code w
24、ith MOV instructions. After all, thats why you use C compilers.Today, machines are so fast that we no longer need to use assembly. It is amazing that people will spend lots of money to buy a machine slightly faster than the one they own, but they wont spend any extra time writing their code in assem
25、bly so it runs faster on the same hardware. Thereare many raging debates about the speed of machines versus the speed of the software, but one fact remains: users always want more speed. On any given machine, the fastest possible programs will be written in assembly language.If you need more speed,
26、you should use a better algorithm rather than switch to assembly language. Why cant you use this better algorithm in assembly language? What if youre already using the best algorithm you can find and its still too slow? This is a totally bogus argumentagainst assembly language. Any algorithm you can
27、 implement in a HLL you can implement in assembly. On the other hand, there are many algorithms you can implement in assembly which you cannot implement in a HLL.Assembly language is not portable. This is an undeniable fact. An 80x86 assembly language program written for an IBM PC will not run on an
28、 Apple Macintosh. Indeed, assembly language programs written for the Apple Macintosh will not run on an Amiga, even though they share the same 680x0 microprocessor. If you need to run your program on different machines, youll have to think long and hard about using assembly language. Using C (or som
29、e other HLL) is no guarantee that your program will be portable. C programs written for the IBM PC wont compile and run on a Macintosh. And even if they did, most Mac owners wouldnt accept the result.Portability is probably the biggest complaint people have against assembly language. They refuse to
30、use assembly because it is not portable, and then they turn around and write equally non-portable programs in C.Yes, there are lots of lies, misconceptions, myths, and half-truths concerning assembly language. Whatever you do, make sure you learn assembly language before forming your own opinions. S
31、peaking out in ignorance may impress others who know less than you do, but it wont impress those who know the truth.2 Whats Right With Assembly Language?An old joke goes something like this: There are three reasons for using assembly language: speed,speed, and more speed. Even those who absolutely h
32、ate assembly language will admit that ifspeed is your primary concern, assembly language is the way to go. Assembly language has several benefits: (1)Speed. Assembly language programs are generally the fastest programs around. (2)Space. Assembly language programs are often the smallest. (3)Capability. You can do things in assembly which are difficult or impossible in HLLs. (4)Knowledge. Your knowledge of assembly language will help you write better programs, even when using HLLs.Assembly language is the uncontested speed champion among