版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、<p><b> 附錄 科技文獻(xiàn)翻譯</b></p><p><b> 英文</b></p><p> The Art of Assembly Language</p><p> 1. What's Wrong With Assembly Language?</p><p>
2、; 2. What's Right With Assembly Language?</p><p> 1. What's Wrong With Assembly Language</p><p> Assembly language has a pretty bad reputation. The common impression about assembly la
3、nguage</p><p> programmers today is that they are all hackers or misguided individuals who need enlightenment.</p><p> Here are the reasons people give for not using assembly:</p><p
4、> ??(1)Assembly is hard to learn.</p><p> ??(2)Assembly is hard to read and understand.</p><p> ??(3)Assembly is hard to debug.</p><p> ??(4)Assembly is hard to maintain.<
5、/p><p> ??(5)Assembly is hard to write.</p><p> ??(6)Assembly language programming is time consuming.</p><p> ?? (7)Improved compiler technology has eliminated the need for assembly
6、 language.</p><p> ?? (8)Today, machines are so fast that we no longer need to use assembly.</p><p> ??(9)If you need more speed, you should use a better algorithm rather than switch to assemb
7、ly language.</p><p> ??(10)Machines have so much memory today, saving space using assembly is not important.</p><p> ??(11)Assembly language is not portable.</p><p> These are so
8、me strong statements indeed!</p><p> Given that this is a book which teaches assembly language programming, written for college level students, written by someone who appears to know what he's talking a
9、bout, your natural tendency is to believe something if it appears in print. Having just read the above, you're starting to assume that assembly must be pretty bad. And that, dear friend, is eighty percent of what'
10、;s wrong with assembly language. That is, people develop some very strong misconceptions about assembly language based on w</p><p> Assembly language users also use high level languages (HLLs); assembly'
11、;s 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
12、 an honest opinion of its capabilities?</p><p> 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 pag
13、es explaining what is wrong with each of the above statements. However, this book is long enough and I felt that very little was gained</p><p> by going on and on about these points. Nonetheless, a brief re
14、buttal to each of the above points is in order, if for no other reason than to keep you from thinking there isn't a decent defense for these statements.</p><p> Assembly is hard to learn. So is any lang
15、uage you don't 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 l
16、anguages 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
17、the other Pascal-like l</p><p> Assembly is hard to read and understand. It sure is, if you don't know it. Most people who make this statement simply don't know assembly. Of course, it's very ea
18、sy to write impossible-to-read assembly language programs. It's 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.<
19、/p><p> Assembly is hard to debug. Same argument as above. If you don't have much experience debugging assembly language programs, it's going to be hard to debug them. Remember what it was like finding
20、 bugs in your first Pascal (or other HLL) programs? Anytime you learn a new programming language you'll have problems debugging programs in that language until you gain</p><p> experience.</p>&l
21、t;p> 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 maintaina
22、ble programs isn't a talent. It's a skill you develop through experience.</p><p> Assembly language is hard. This statement actually has a ring of truth to it. For the longest time assembly language
23、 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 pack
24、age 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</p><p> companion diskette.<
25、/p><p> 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
26、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 im
27、plement something in assembly language. It is true using a HLL will save some t</p><p> Improved compiler technology has eliminated the need for assembly language. This isn't true and probably never wil
28、l 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 langu
29、age 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</p><p> hand-compiled code against that
30、 produced by a compiler. Compilers do a much better job of compiling than humans. Then again, you'll never catch an assembly language programmer writing "C code with MOV instructions." After all, that's
31、 why you use C compilers.</p><p> 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 ow
32、n, but they won't spend any extra time writing their code in assembly so it runs faster on the same hardware. There</p><p> are many raging debates about the speed of machines versus the speed of the so
33、ftware, but one fact remains: users always want more speed. On any given machine, the fastest possible programs will be written in assembly language.</p><p> If you need more speed, you should use a better
34、algorithm rather than switch to assembly language. Why can't you use this better algorithm in assembly language? What if you're already using the best algorithm you can find and it's still too slow? This is a
35、 totally bogus argument</p><p> against 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
36、which you cannot implement in a HLL.</p><p> 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. Indee
37、d, 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, you'll have to thin
38、k long and hard about using assembly language. Using C (or some other HLL) is no guarantee that your program will be portab</p><p> Portability is probably the biggest complaint people have against assembly
39、 language. They refuse to use assembly because it is not portable, and then they turn around and write equally non-portable programs in C.</p><p> Yes, there are lots of lies, misconceptions, myths, and hal
40、f-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 won't imp
41、ress those who know the truth.</p><p> 2 What's Right With Assembly Language?</p><p> An old joke goes something like this: "There are three reasons for using assembly language: speed
42、,</p><p> speed, and more speed." Even those who absolutely hate assembly language will admit that if</p><p> speed is your primary concern, assembly language is the way to go. Assembly l
43、anguage has several benefits:</p><p> ??(1)Speed. Assembly language programs are generally the fastest programs around.</p><p> ??(2)Space. Assembly language programs are often the smallest.&l
44、t;/p><p> ??(3)Capability. You can do things in assembly which are difficult or impossible in HLLs.</p><p> ??(4)Knowledge. Your knowledge of assembly language will help you write better programs
45、, even when using HLLs.</p><p> Assembly language is the uncontested speed champion among programming languages. An expert</p><p> assembly language programmer will almost always produce a fas
46、ter 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 codin
47、g in assembly language; even greater improvement is possible if you're not using an</p><p> optimizing compiler. Alas, speedups on the order of five to ten times are generally not achieved by beginning
48、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 people's claims that programmers no longer ha
49、ve to worry about memory</p><p> constraints, 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
50、 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 app
51、lication. Saving space saves money. Pure and simple. If a program requires 1.5 megabytes, it will not fit o</p><p> Capability is another reason people resort to assembly language. HLLs are an abstraction o
52、f 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, features</p><p>
53、 which 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 microprocesso
54、rs. 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 spe
55、cific I/O operations. In assembly language you have no such r</p><p> Of course, another reason for learning assembly language is just for the knowledge. Now some of you may be thinking, "Gee, that wou
56、ld be wonderful, but I've got lots to do. My time would be better spent writing code than learning assembly language." There are some practical reasons for</p><p> learning assembly, even if you ne
57、ver intend to write a single line of assembly code. If you know assembly language well, you'll have an appreciation for the compiler, and you'll know exactly what the compiler is doing with all those HLL statemen
58、ts. Once you see how compilers translate seemingly innocuous statements into a ton of machine code, you'll want to search for better ways to accomplish the same thing. Good assembly language programmers make better H
59、LL programmers because they understand </p><p> doing with their code. Those who don't know assembly language will accept the poor performance their compiler produces and simply shrug it off.</p>
60、<p> Yes, assembly language is definitely worth the effort. The only scary thing is that once you learn it really well, you'll probably start using it far more than you ever dreamed you would. That is a common
61、 malady among assembly language programmers. Seems they can't stand what the compilers are doing with their programs.</p><p><b> 譯文</b></p><p><b> 匯編語(yǔ)言的藝術(shù)</b></p
62、><p> 1.匯編語(yǔ)言的不足之處是什么?</p><p> 2.匯編語(yǔ)言的優(yōu)勢(shì)是什么?</p><p> 1.匯編語(yǔ)言的不足是什么</p><p> 匯編語(yǔ)言現(xiàn)在的名聲很不好,人們對(duì)匯編程序員普遍的印象是:他們不是黑客就是一些受到錯(cuò)誤思想指引的,需要?jiǎng)e人開(kāi)導(dǎo)的人。下面是人們所給出的若干條不使用匯編語(yǔ)言的理由:</p>&l
63、t;p> ?。?)匯編語(yǔ)言學(xué)起來(lái)很困難;</p><p> ?。?)閱讀和理解匯編程序很困難;</p><p> ?。?)調(diào)試匯編程序很困難;</p><p> (4)匯編程序難維護(hù);</p><p> ?。?)編寫(xiě)匯編程序很困難;</p><p> ?。?)編寫(xiě)匯編程序很耗費(fèi)時(shí)間;</p>&l
64、t;p> (7)日益改進(jìn)的編譯技術(shù)使得匯編語(yǔ)言已不再重要;</p><p> ?。?)目前計(jì)算機(jī)的運(yùn)行速度已經(jīng)足夠快了,再去使用匯編語(yǔ)言已顯得多余;</p><p> ?。?)如果你想要追求更快的計(jì)算機(jī)運(yùn)行速度,你應(yīng)該去使用一個(gè)更高效的算法而不是轉(zhuǎn)向去借助于匯編語(yǔ)言;</p><p> ?。?0)目前計(jì)算機(jī)的內(nèi)存容量已經(jīng)足夠大了,通過(guò)使用匯編語(yǔ)言來(lái)達(dá)到節(jié)省內(nèi)
65、存的這種做法已不再可?。?lt;/p><p> ?。?1)匯編語(yǔ)言依賴(lài)于具體的機(jī)器硬件環(huán)境,不具備良好的移植性。</p><p> 假如這是一本為具有大學(xué)水平的讀者編寫(xiě)的匯編程序設(shè)計(jì)的教材,并且看上去該書(shū)作者的寫(xiě)作意圖明確,因此作為一名讀者,你會(huì)自然而然地去相信書(shū)中所寫(xiě)的內(nèi)容,讀者們,當(dāng)你們讀到這里的時(shí)候,你們肯定會(huì)開(kāi)始去猜測(cè)到匯編語(yǔ)言一定有許多不盡如人意的地方了。確實(shí),匯編語(yǔ)言80%的不足
66、之處就在于人們根據(jù)從他們的朋友,老師或者一些與匯編語(yǔ)言有關(guān)的文章或書(shū)籍中所獲得的信息對(duì)匯編語(yǔ)言形成了一些錯(cuò)誤的看法。誠(chéng)然,匯編語(yǔ)言確實(shí)存在著許多的不足之處,但是,這些不足在那些對(duì)匯編語(yǔ)言的錯(cuò)誤認(rèn)識(shí)影響下被嚴(yán)重夸大了。究竟有多少人愿意根據(jù)他們對(duì)匯編語(yǔ)言的了解或者所讀過(guò)的有關(guān)匯編語(yǔ)言的文章來(lái)發(fā)表對(duì)匯編語(yǔ)言的看法是令人想知道的。</p><p> 匯編語(yǔ)言的使用者也使用一些高級(jí)語(yǔ)言,而那些對(duì)匯編語(yǔ)言的反對(duì)者卻很少使用
67、匯編語(yǔ)言。那么,誰(shuí)又會(huì)相信,一個(gè)精通多種編程語(yǔ)言但卻沒(méi)有花時(shí)間去學(xué)習(xí)匯編語(yǔ)言的人能夠形成對(duì)匯編語(yǔ)言如實(shí)、客觀的評(píng)價(jià)呢?</p><p> 當(dāng)我和別人交談時(shí),我會(huì)盡可能的表達(dá)出我的以上觀點(diǎn),在本章的前言中,我準(zhǔn)備花十頁(yè)紙去逐個(gè)解釋前面列出的每一種觀點(diǎn),盡管這本書(shū)已經(jīng)夠長(zhǎng)了,但是對(duì)前面列出的這些觀點(diǎn)進(jìn)行簡(jiǎn)明扼要的反駁還是有必要的。否則你會(huì)認(rèn)為目前還沒(méi)有人站出來(lái)對(duì)這些觀點(diǎn)進(jìn)行反駁。</p><p&
68、gt; 匯編語(yǔ)言學(xué)起來(lái)很困難。不僅是學(xué)習(xí)匯編語(yǔ)言如此,當(dāng)你學(xué)習(xí)起一門(mén)不熟悉的程序設(shè)計(jì)語(yǔ)言時(shí),情況也是如此。你不如嘗試著去學(xué)像APL,Prolog或者Smalltalk這樣的語(yǔ)言,你就會(huì)有這樣的感受了。如果你一旦學(xué)過(guò)了Pascal語(yǔ)言,那么當(dāng)你在去學(xué)習(xí)像C、Basic、Fortran、Modula-2或者Ada這樣的語(yǔ)言時(shí),就會(huì)變得相當(dāng)容易了。為什么呢?因?yàn)檫@些語(yǔ)言都和Pascal語(yǔ)言很相似,換句話說(shuō),當(dāng)你學(xué)習(xí)起一門(mén)不熟悉的語(yǔ)言時(shí),比如
69、說(shuō)Prolog,難度就大多了。同樣,因?yàn)閰R編語(yǔ)言跟Pascal語(yǔ)言有很大的不同,所以學(xué)習(xí)起匯編語(yǔ)言來(lái)要比你學(xué)習(xí)起和Pascal很相似的那些語(yǔ)言難度大了很多,不過(guò)我相信學(xué)習(xí)匯編語(yǔ)言應(yīng)該要比你第一次學(xué)習(xí)起編程語(yǔ)言時(shí)要輕松一些。</p><p> 閱讀和理解匯編程序很困難。當(dāng)然,如果你沒(méi)學(xué)過(guò)匯編語(yǔ)言,情況肯定會(huì)是這樣。但是那些持有這種觀點(diǎn)的大多數(shù)人并不真正了解匯編語(yǔ)言,如果你胡亂寫(xiě)出一個(gè)匯編程序,那肯定是讓人無(wú)法閱讀
70、和理解。實(shí)際上,匯編語(yǔ)言和其它語(yǔ)言一樣也是很好學(xué)習(xí)的。</p><p> 調(diào)試匯編程序很困難。當(dāng)然,如果你對(duì)匯編程序的調(diào)試技術(shù)不熟悉的話,結(jié)果肯定是調(diào)試起來(lái)很困難。你還記得你是怎樣調(diào)試出你的第一個(gè)Pascal程序中的錯(cuò)誤了嗎?因此,當(dāng)你一開(kāi)始接觸一種新的程序設(shè)計(jì)語(yǔ)言時(shí),在調(diào)試其程序出現(xiàn)種種困難是在所難免的,隨著你對(duì)這種編程語(yǔ)言的調(diào)試技術(shù)不斷掌握,情況會(huì)越來(lái)越好。</p><p> 匯編
71、程序難維護(hù)。實(shí)際上,C語(yǔ)言程序也難維護(hù),想要使程序運(yùn)行相當(dāng)長(zhǎng)的一段時(shí)間而不出現(xiàn)任何問(wèn)題相當(dāng)困難。一些有經(jīng)驗(yàn)的匯編程序員在做程序的維護(hù)工作時(shí)也常常顯得很吃力。但是能編寫(xiě)出一個(gè)高質(zhì)量的,好維護(hù)的程序的人并不能稱(chēng)之為天才。這種技能實(shí)際上可以通過(guò)不斷的積累編程經(jīng)驗(yàn)而獲得。</p><p> 編寫(xiě)匯編程序很困難。這一點(diǎn)從過(guò)去來(lái)看倒是實(shí)際情況。在過(guò)去很長(zhǎng)一段時(shí)間里,匯編程序員在編寫(xiě)程序時(shí)完全是從零開(kāi)始。然而,像C語(yǔ)言,Ad
72、a語(yǔ)言和Modual-2語(yǔ)言的程序員卻一直享受著其語(yǔ)言中的標(biāo)準(zhǔn)函數(shù)庫(kù)給編程帶來(lái)的便利。這些標(biāo)準(zhǔn)函數(shù)庫(kù)中的函數(shù)能夠用來(lái)解決許多實(shí)際編程問(wèn)題,而匯編程序員卻沒(méi)有現(xiàn)成的標(biāo)準(zhǔn)函數(shù)庫(kù)可供利用,只有完全通過(guò)自己來(lái)編寫(xiě)程序。但是在本書(shū)中,我采用了由美國(guó)加利弗利亞大學(xué)為使用80X86匯編語(yǔ)言的程序編寫(xiě)的一個(gè)標(biāo)準(zhǔn)函數(shù)庫(kù),匯編程序員可以通過(guò)調(diào)用這個(gè)標(biāo)準(zhǔn)函數(shù)庫(kù)中的函數(shù)而大大減輕編寫(xiě)代碼時(shí)的工作量,這就像C語(yǔ)言的標(biāo)準(zhǔn)函數(shù)庫(kù)對(duì)編寫(xiě)C程序所起的作用一樣。</
73、p><p> 編寫(xiě)匯編程序很耗費(fèi)時(shí)間。軟件工程師們估計(jì),軟件開(kāi)發(fā)者在一個(gè)軟件開(kāi)發(fā)周期中僅僅花費(fèi)大約30%的時(shí)間來(lái)編寫(xiě)代碼,即使軟件開(kāi)發(fā)者用匯編語(yǔ)言花了比使用一些高級(jí)語(yǔ)言?xún)杀兜臅r(shí)間來(lái)編寫(xiě)代碼,其對(duì)整個(gè)軟件項(xiàng)目完成時(shí)間的影響也只有15%的不同。事實(shí)上,一個(gè)優(yōu)秀的匯編程序員并不需要花這么多時(shí)間來(lái)編寫(xiě)代碼。當(dāng)然,使用一種高級(jí)語(yǔ)言來(lái)編寫(xiě)代碼會(huì)比使用匯編語(yǔ)言節(jié)省一些時(shí)間,但是這種時(shí)間上的節(jié)省并不能和使用匯編語(yǔ)言所帶來(lái)的好處相提
74、并論。</p><p> 日益改進(jìn)的編譯技術(shù)使得匯編語(yǔ)言已不再重要。首先,這種觀點(diǎn)是錯(cuò)誤的而且很可能永遠(yuǎn)是這樣。針對(duì)編譯器的優(yōu)化研究正在日益取得進(jìn)展,然而對(duì)于同一問(wèn)題匯編程序員所編寫(xiě)出的代碼和使用高級(jí)語(yǔ)言編寫(xiě)并經(jīng)過(guò)編譯器翻譯后所生成的匯編代碼還是有所不同。如果一名匯編程序員先用C語(yǔ)言編寫(xiě)出代碼然后再手工地將它們轉(zhuǎn)換成等價(jià)的匯編代碼的話,按理說(shuō)一個(gè)好的C編譯器應(yīng)該產(chǎn)生跟手工轉(zhuǎn)換相同或者更加高效的匯編代碼來(lái),但是實(shí)
75、際情況并不是這樣。不僅如此,你也很少會(huì)遇到一位愿意做將C程序代碼轉(zhuǎn)換成等價(jià)的匯編代碼工作的匯編程序員,也許,這也就是那些反對(duì)使用匯編語(yǔ)言的人為什么用C編譯器的原因了吧。</p><p> 目前計(jì)算機(jī)的運(yùn)行速度已經(jīng)足夠快了,再去使用匯編語(yǔ)言已顯得多余。我始終覺(jué)得奇怪:人們總是愿意花許多錢(qián)去購(gòu)買(mǎi)一臺(tái)速度更快的計(jì)算機(jī),卻不愿意花費(fèi)時(shí)間去用匯編語(yǔ)言編寫(xiě)他們的代碼以便獲得更快的運(yùn)行速度。關(guān)于計(jì)算機(jī)的運(yùn)行速度和程序的運(yùn)行速
76、度之間存在著許多激烈的爭(zhēng)論,但是有一點(diǎn)總是正確的,那就是在一臺(tái)給定的計(jì)算機(jī)上,用匯編語(yǔ)言編寫(xiě)出來(lái)的程序的運(yùn)行速度最快。</p><p> 如果你想要追求更快的計(jì)算機(jī)運(yùn)行速度,你應(yīng)該去使用一個(gè)高效的算法而不是轉(zhuǎn)向去借助于匯編語(yǔ)言。其實(shí),上述觀點(diǎn)并不正確,難道匯編語(yǔ)言中就沒(méi)有一些高效的算法了嗎?在任何高級(jí)語(yǔ)言中能夠使用的算法就一定能夠在匯編語(yǔ)言中使用;但是卻有許多能在匯編語(yǔ)言中使用的算法不能在高級(jí)語(yǔ)言中使用。<
77、;/p><p> 目前計(jì)算機(jī)的內(nèi)存容量已經(jīng)足夠大了,通過(guò)使用匯編語(yǔ)言來(lái)達(dá)到節(jié)省內(nèi)存的這種做法已不再可取。有一句俗語(yǔ)叫得寸進(jìn)尺,這一俗語(yǔ)用在當(dāng)今的程序設(shè)計(jì)中再合適不過(guò)了。在過(guò)去很長(zhǎng)一段時(shí)間里,程序員們所使用機(jī)器的內(nèi)存容量都是4KB,后來(lái),隨著機(jī)器的內(nèi)存容量擴(kuò)展為32KB或者64KB,程序員們所編寫(xiě)出來(lái)的程序的大小也隨之增長(zhǎng)。如今,許多計(jì)算機(jī)的內(nèi)存容量已經(jīng)是32M或是64M了,而程序員們所編寫(xiě)出的程序大小更是繼續(xù)增長(zhǎng),
78、有的程序甚至在運(yùn)行時(shí)需要占用整個(gè)內(nèi)存空間。因此希望程序員在編寫(xiě)程序時(shí)盡量短小精悍,不能因?yàn)楝F(xiàn)在計(jì)算機(jī)的內(nèi)存容量大了,而去盲目的編寫(xiě)一些大程序。</p><p> 匯編語(yǔ)言依賴(lài)于具體的機(jī)器硬件環(huán)境,不具備良好的移植性,確實(shí),這是一個(gè)不可否認(rèn)的事實(shí)。一個(gè)為IBM品牌機(jī)編寫(xiě)的80X86匯編程序不能夠在一臺(tái)蘋(píng)果機(jī)上運(yùn)行;同樣地,一個(gè)為蘋(píng)果機(jī)編寫(xiě)的匯編程序也不能在其它品牌的計(jì)算機(jī)上運(yùn)行,即使兩臺(tái)機(jī)器都有相同的680
79、15;0微處理器。如果你需要將你所編寫(xiě)的匯編程序能在不同的計(jì)算機(jī)上運(yùn)行,那么你在編寫(xiě)匯編代碼時(shí)需要花費(fèi)很多的心思。但是用C語(yǔ)言編寫(xiě)的程序也并不能保證具有良好的移植性。一個(gè)為IBM計(jì)算機(jī)編寫(xiě)的C程序也不能夠在一臺(tái)麥金塔計(jì)算機(jī)上編譯通過(guò)并運(yùn)行。</p><p> 可移植性差可能是人們反對(duì)使用匯編語(yǔ)言最主要的原因了。但是那些因?yàn)閰R編語(yǔ)言可移植性差而拒絕使用該語(yǔ)言的人卻轉(zhuǎn)向去使用移植性同樣很差的C語(yǔ)言。</p&g
80、t;<p> 確實(shí),關(guān)于匯編語(yǔ)言充斥著太多的謊言、錯(cuò)誤思想、謎和半真半假的話。但是無(wú)論你怎樣去評(píng)價(jià)匯編語(yǔ)言,你必須在形成你自己對(duì)匯編語(yǔ)言的觀點(diǎn)之前首先學(xué)過(guò)匯編語(yǔ)言。否則,你隨口說(shuō)出的關(guān)于匯編語(yǔ)言的看法也許會(huì)對(duì)那些比你了解匯編語(yǔ)言更少的人產(chǎn)生很大的影響。</p><p> 2.匯編語(yǔ)言的優(yōu)勢(shì)是什么</p><p> 有一個(gè)古老的笑話是這樣說(shuō)的:使用匯編語(yǔ)言有三個(gè)理由,那就
81、是速度、速度、更快的速度。如果你對(duì)機(jī)器的運(yùn)行速度最為關(guān)心的話,那么即使十分討厭匯編語(yǔ)言的人也不得不承認(rèn),匯編語(yǔ)言是一個(gè)不錯(cuò)的選擇??偟恼f(shuō)來(lái),匯編語(yǔ)言有如下幾個(gè)特點(diǎn):</p><p> ?。?)速度 一般說(shuō)來(lái),用匯編語(yǔ)言編寫(xiě)出的程序具有最快的運(yùn)行速度。</p><p> ?。?)空間 匯編程序往往是最簡(jiǎn)潔的。</p><p> ?。?)能力 我們能夠用匯編語(yǔ)言編
82、寫(xiě)出一些在高級(jí)語(yǔ)言中很困難或者根本無(wú)法實(shí)現(xiàn)的程序。</p><p> ?。?)知識(shí) 你所掌握的關(guān)于匯編語(yǔ)言的知識(shí)將有助你編寫(xiě)出質(zhì)量更好的程序。</p><p> 匯編程序比用其它程序設(shè)計(jì)語(yǔ)言編寫(xiě)出的程序具有更快的運(yùn)行速度,一名熟練的匯編程序員幾乎一直能編寫(xiě)出比一名熟練的C程序員運(yùn)行速度更快的程序。不僅如此,你能夠通過(guò)仔細(xì)地編寫(xiě)匯編代碼而將程序的運(yùn)行速度提高五分之一或者十分之一。甚至即使
83、你的程序不通過(guò)編譯器的優(yōu)化,將程序的運(yùn)行速度進(jìn)行大幅提升也是可能的。</p><p> 盡管一些人認(rèn)為程序員可以不用擔(dān)心計(jì)算機(jī)內(nèi)存容量的限制,但是我們?nèi)匀恍枰绦騿T去編寫(xiě)一些簡(jiǎn)潔的程序。針對(duì)同一問(wèn)題編寫(xiě)出的匯編程序通常要比用高級(jí)語(yǔ)言編寫(xiě)出的程序占用內(nèi)存空間少。節(jié)省內(nèi)存空間就意味著省錢(qián),這個(gè)道理相當(dāng)簡(jiǎn)單易懂。如果一個(gè)程序有1.5MB,那么這個(gè)程序就無(wú)法存儲(chǔ)在一張1.44M的軟盤(pán)中;同樣地,如果一個(gè)應(yīng)用程序需要2M
84、B的內(nèi)存空間,而計(jì)算機(jī)中只有1M的內(nèi)存空間,那么該用戶就不得不去再安裝一條1M的內(nèi)存條。即使是在一臺(tái)內(nèi)存容量達(dá)32M或者更大的計(jì)算機(jī)上,也是應(yīng)該盡量避免編寫(xiě)大的應(yīng)用程序。許多用戶對(duì)他們的計(jì)算機(jī)配置了超過(guò)8M的內(nèi)存,以便他們能同時(shí)運(yùn)行多個(gè)程序,但是如果應(yīng)用程序都很大的話,這樣的目的往往達(dá)不到。使用虛擬內(nèi)存雖然可行,但畢竟不是針對(duì)此問(wèn)題的一個(gè)好的解決方案。</p><p> 能力是人們使用匯編語(yǔ)言的另一個(gè)理由。使
85、用高級(jí)語(yǔ)言編寫(xiě)出的程序獨(dú)立于具體的機(jī)器硬件環(huán)境,它們很少考慮一臺(tái)機(jī)器的具體特點(diǎn)。然而這正是匯編語(yǔ)言的長(zhǎng)處,如果你想去充分地利用一臺(tái)機(jī)器的具體硬件環(huán)境,那么你最好去選擇匯編語(yǔ)言。一個(gè)可以很好的說(shuō)明問(wèn)題的例子就是在匯編語(yǔ)言直接支持對(duì)機(jī)器各種硬件的訪問(wèn)與操作,并且有許多相應(yīng)的指令可進(jìn)行具體實(shí)施,而像C這樣的高級(jí)語(yǔ)言就不能如此。因此可以說(shuō),使用匯編語(yǔ)言可以進(jìn)行最底層的機(jī)器硬件編程,而這一特點(diǎn)卻是如今許多高級(jí)語(yǔ)言所不具備的。</p>
86、<p> 另一個(gè)學(xué)習(xí)匯編語(yǔ)言的理由是為了單純的學(xué)習(xí)一些知識(shí)。也許某些人會(huì)認(rèn)為,我們最好應(yīng)該把時(shí)間花在其它一些更有意義的事情上,而不是花在純粹的學(xué)習(xí)一些匯編語(yǔ)言知識(shí)上。但是,即使你永遠(yuǎn)也不打算去編寫(xiě)一行匯編代碼,我仍然可以拿出一些理由來(lái)說(shuō)服你學(xué)習(xí)匯編語(yǔ)言。首先,如果你很了解匯編語(yǔ)言的話,你就會(huì)對(duì)編譯器有了一個(gè)更深刻的認(rèn)識(shí),并且會(huì)確切地知道編譯器在編譯時(shí)是如何將程序中的語(yǔ)句翻譯成機(jī)器代碼的。一個(gè)匯編程序員一般均勝過(guò)一名高級(jí)語(yǔ)言
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 眾賞文庫(kù)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 單片機(jī)外文翻譯---匯編語(yǔ)言的藝術(shù)
- 匯編語(yǔ)言指令
- 《匯編語(yǔ)言》試卷a
- 匯編語(yǔ)言程序例
- 匯編語(yǔ)言實(shí)驗(yàn)
- 匯編語(yǔ)言題目答案
- 匯編語(yǔ)言常用指令
- 匯編語(yǔ)言期末習(xí)題
- 匯編語(yǔ)言編程題
- 匯編語(yǔ)言到C語(yǔ)言翻譯軟件的設(shè)計(jì)與實(shí)現(xiàn).pdf
- 匯編語(yǔ)言課程設(shè)計(jì)--用匯編語(yǔ)言實(shí)現(xiàn)顯示系統(tǒng)時(shí)間的程序
- 《匯編語(yǔ)言》課程設(shè)計(jì)---用匯編語(yǔ)言進(jìn)行音樂(lè)動(dòng)畫(huà)功能的實(shí)現(xiàn)
- 匯編語(yǔ)言課程設(shè)計(jì)
- 匯編語(yǔ)言練習(xí)題
- 匯編語(yǔ)言程序設(shè)計(jì)
- 匯編語(yǔ)言習(xí)題答案-(3)
- 匯編語(yǔ)言的工作環(huán)境
- 基于匯編語(yǔ)言的數(shù)字時(shí)鐘
- 匯編語(yǔ)言習(xí)題答案3
- 匯編語(yǔ)言指令詳解大全
評(píng)論
0/150
提交評(píng)論