单片机外文翻译—汇编语言的艺术(译文+英文).doc_第1页
单片机外文翻译—汇编语言的艺术(译文+英文).doc_第2页
单片机外文翻译—汇编语言的艺术(译文+英文).doc_第3页
单片机外文翻译—汇编语言的艺术(译文+英文).doc_第4页
单片机外文翻译—汇编语言的艺术(译文+英文).doc_第5页
免费预览已结束,剩余8页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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 hackers 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 programming 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 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 talking 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 misconceptions 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 time 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 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 time 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. 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 hard 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, 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.Assembly 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 experience, 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) programs? 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 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-inventing 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 time 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 programmers. 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 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 assembly 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 getting 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 produce 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 with 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 assembly 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, 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 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 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 some 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 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. Speaking 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 hate 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 programming languages. An expertassembly language programmer will almost always produce a faster program than an expert C programmer. While certain programs may not benefit much from implementation in assembly, you can speed up many programs by a factor of five or ten over their HLL counterparts by careful coding in assembly language; even greater improvement is possible if youre not using anoptimizing compiler. Alas, speedups on the order of five to ten times are generally not achieved by beginning assembly language programmers. However, if you spend the time to learn assembly language really well, you too can achieve these impressive performance gains. Despite some peoples claims that programmers no longer have to worry about memoryconstraints, there are many programmers who need to write smaller programs. Assembly language programs are often less than one-half the size of comparable HLL programs. This is especially impressive when you consider the fact that data items generally consume the same amount of space in both types of programs, and that data is responsible for a good amount of the space used by a typical application. Saving space saves money. Pure and simple. If a program requires 1.5 megabytes, it will not fit on a 1.44 Mbyte floppy. Likewise, if an application requires 2 megabytes RAM, the user will have to install an extra megabyte if there is only one available in the machine. Even on big machines with 32 or more megabytes, writing gigantic applications isnt excusable. Most users put more than eight megabytes in their machines so they can run multiple programs from memory at one time. The bigger a program is, the fewer applications will be able to coexist in memory with it. Virtual memory isnt a particularly attractive solution either. With virtual memory, the bigger an application is, the slower the system will run as a result of that programs size.Capability is another reason people resort to assembly language. HLLs are an abstraction of a typical machine architecture. They are designed to be independent of the particular machine architecture. As a result, they rarely take into account any special features of the machine, featureswhich are available to assembly language programmers. If you want to use such features, you will need to use assembly language. A really good example is the input/output instructions available on the 80x86 microprocessors. These instructions let you directly access certain I/O devices on the computer. In general, such access is not part of any high level language. Indeed, some languages like C pride themselves on not supporting any specific I/O operations. In assembly language you have no such restrictions. Anything you can do on the machine you can do in assembly language. This is definitely not the case with most HLLs.Of course, another reason for learning assembly language is just for the knowledge. Now some of you may be thinking, Gee, that would be wonderful, but Ive got lots to do. My time would be better spent writing code than learning assembly language. There are some practical reasons forlearning assembly, even if you never intend to write a single line of assembly code. If you know assembly language well, youll have an appreciation for the compiler, and youll know exactly what the compiler is doing with all those HLL statements. Once you see how compilers translate seemingly innocuous statements into a ton of machine code, youll want to search for better ways to accomplish the same thing. Good assembly language programmers make better HLL programmers because they understand the limitations of the compiler and they know what itsdoing with their code. Those who dont know assembly language will accept the poor performance their compiler produces and simply shrug it off.Yes, assembly language is definitely worth the effort. The only scary thing is that once you learn it really well, youll probably start using it far more than you ever dreamed you would. That is a common malady among assembly language programmers. Seems they cant stand what the compilers are doing with their programs.译文汇编语言的艺术1.汇编语言的不足之处是什么?2.汇编语言的优势是什么?1.汇编语言的不足是什么汇编语言现在的名声很不好,人们对汇编程序员普遍的印象是:他们不是黑客就是一些受到错误思想指引的,需要别人开导的人。下面是人们所给出的若干条不使用汇编语言的理由:(1)汇编语言学起来很困难;(2)阅读和理解汇编程序很困难;(3)调试汇编程序很困难;(4)汇编程序难维护;(5)编写汇编程序很困难;(6)编写汇编程序很耗费时间;(7)日益改进的编译技术使得汇编语言已不再重要;(8)目前计算机的运行速度已经足够快了,再去使用汇编语言已显得多余;(9)如果你想要追求更快的计算机运行速度,你应该去使用一个更高效的算法而不是转向去借助于汇编语言;(10)目前计算机的内存容量已经足够大了,通过使用汇编语言来达到节省内存的这种做法已不再可取;(11)汇编语言依赖于具体的机器硬件环境,不具备良好的移植性。假如这是一本为具有大学水平的读者编写的汇编程序设计的教材,并且看上去该书作者的写作意图明确,因此作为一名读者,你会自然而然地去相信书中所写的内容,读者们,当你们读到这里的时候,你们肯定会开始去猜测到汇编语言一定有许多不尽如人意的地方了。确实,汇编语言80%的不足之处就在于人们根据从他们的朋友,老师或者一些与汇编语言有关的文章或书籍中所获得的信息对汇编语言形成了一些错误的看法。诚然,汇编语言确实存在着许多的不足之处,但是,这些不足在那些对汇编语言的错误认识影响下被严重夸大了。究竟有多少人愿意根据他们对汇编语言的了解或者所读过的有关汇编语言的文章来发表对汇编语言的看法是令人想知道的。汇编语言的使用者也使用一些高级语言,而那些对汇编语言的反对者却很少使用汇编语言。那么,谁又会相信,一个精通多种编程语言但却没有花时间去学习汇编语言的人能够形成对汇编语言如实、客观的评价呢?当我和别人交谈时,我会尽可能的表达出我的以上观点,在本章的前言中,我准备花十页纸去逐个解释前面列出的每一种观点,尽管这本书已经够长了,但是对前面列出的这些观点进行简明扼要的反驳还是有必要的。否则你会认为目前还没有人站出来对这些观点进行反驳。汇编语言学起来很困难。不仅是学习汇编语言如此,当你学习起一门不熟悉的程序设计语言时,情况也是如此。你不如尝试着去学像APL,Prolog或者Smalltalk这样的语言,你就会有这样的感受了。如果你一旦学过了Pascal语言,那么当你在去学习像C、Basic、Fortran、Modula-2或者Ada这样的语言时,就会变得相当容易了。为什么呢?因为这些语言都和Pascal语言很相似,换句话说,当你学习起一门不熟悉的语言时,比如说Prolog,难度就大多了。同样,因为汇编语言跟Pascal语言有很大的不同,所以学习起汇编语言来要比你学习起和Pascal很相似的那些语言难度大了很多,不过我相信学习汇编语言应该要比你第一次学习起编程语言时要轻松一些。阅读和理解汇编程序很困难。当然,如果你没学过汇编语言,情况肯定会是这样。但是那些持有这种观点的大多数人并不真正了解汇编语言,如果你胡乱写出一个汇编程序,那肯定是让人无法阅读和理解。实际上,汇编语言和其它语言一样也是很好学习的。调试汇编程序很困难。当然,如果你对汇编程序的调试技术不熟悉的话,结果肯定是调试起来很困难。你还记得你是怎样调试出你的第一个Pascal程序中的错误了吗?因此,当你一开始接触一种新的程序设计语言时,在调试其程序出现种种困难是在所难免的,随着你对这种编程语言的调试技术不断掌握,情况会越来越好。汇编程序难维护。实际上,C语言程序也难维护,想要使程序运行相当长的一段时间而不出现任何问题相当困难。一些有经验的汇编程序员在做程序的维护工作时也常常显得很吃力。但是能编写出一个高质量的,好维护的程序的人并不能称之为天才。这种技能实际上可以通过不断的积累编程经验而获得。编写汇编程序很困难。这一点从过去来看倒是实际情况。在过去很长一段时间里,汇编程序员在编写程序时完全是从零开始。然而,像C语言,Ada语言和Modual-2语言的程序员却一直享受着其语言中的标准函数库给编程带来的便利。这些标准函数库中的函数能够用来解决许多实际编程问题,而汇编程序员却没有现成的标准函数库可供利用,只有完全通过自己来编写程序。但是在本书中,我采用了由美国加利弗利亚大学为使用80X86汇编语言的程序编写的一个标准函数库,汇编程序员可以通过调用这个标准函数库中的函数而大大减轻编写代码时的工作量,这就像C语言的标准函数库对编写C程序所起的作用一样。编写汇编程序很耗费时间。软件工程师们估计,软件开发者在一个软件开发周期中仅仅花费大约30%的时间来编写代码,即使软件开发者用汇编语言花了比使用一些高级语言两倍的时间来编写代码,其对整个软件项目完成时间的影响也只有15%的不同。事实上,一个优秀的汇编程序员并不需要花这么多时间来编写代码。当然,使用一种高级语言来编写代码会比使用汇编语言节省一些时间,但是这种时间上的节省并不能和使用汇编语言所带来的好处相提并论。日益改进的编译技术使得汇编语言已不再重要。首先,这种观点是错误的而且很可能永远是这样。针对编译器的优化研究正在日益取得进展,然而对于同一问题汇编程序员所编写出的代码和使用高级语言编写并经过编译器翻译后所生成的汇编代码还是有所不同。如果一名汇编程序员先用C语言编写出代码然后再手工地将它们转换成等价的汇编代码的话,按理说一个好的C编译器应该产生跟手工转换相同或者更加高效的汇编代码来,但是实际情况并不是这样。不仅如此,你也很少会遇到一位愿意做将C程序代码转换成等价的汇编代码工作的汇编程序员,也许,这也就是那些反对使用汇编语言的人为什么用C编译器的原因了吧。目前计算机的运行速度已经足够快了,再去使用汇编语言已显得多余。我始终觉得奇怪:人们总是愿意花许多钱去购买一台速度更快的计算机,却不愿意花费时间去用汇编语言编写他们的代码以便获得更快的运行速度。关于计算机的运行速度和程序的运行速度之间存在着许多激烈的争论,但是有一点总是正确的,那就是在一台给定的计算机上,用汇编语言编写出来的程序的运行速度最快。如果你想要追求更快的计算机运行速度,你应该去使用一个高效的算法而不是转向去借助于汇编语言。其实,上述观点并不正确,难道汇编语言中就没有一些高效的算法了吗?在任何高级语言中能够使用的算法就一定能够在汇编语言中使用;但是却有许多能在汇编语言中使用的算法不能在高级语言中使用。目前计算机的内存容量已经足够大了,通过使用汇编语言来达到节省内存的这种做法已不再可取。有一句俗语叫得寸进尺,这一俗语用在当今的程序设计中再合适不过了。在过去很长一段时间里,程序员们所使用机器的内存容量都是4KB,后来,随着机器的内存容量扩展为32KB或者64KB,程序员们所编写出来的程序

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论