【文章內(nèi)容簡(jiǎn)介】
t run on an Amiga, even though they share the same 680x0 microprocessor. If you need to run your program on different machines, you39。ll 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 won39。t pile and run on a Macintosh. And even if they did, most Mac owners wouldn39。t accept the result. Portability is probably the biggest plaint people have against assembly language. They refuse to use assembly because it is not portable, and then they turn around and write equally nonportable programs in C. Yes, there are lots of lies, misconceptions, myths, and halftruths 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 won39。t impress those who know the truth. 2 What39。s 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 if 5 speed 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 expert assembly 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 you39。re not using an optimizing piler. 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 people39。s claims that programmers no longer have to worry about memory constraints, there are many programmers who need to write smaller programs. Assembly language programs are often less than onehalf the size of parable 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 megabytes, it will not fit on a 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 isn39。t 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 isn39。t a particularly attractive solution either. With virtual memory, the bigger an application is, the slower the system will run as a result of that program39。s size. 6 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, features 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 microprocessors. These instructions let