单片机外文翻译汇编语言的艺术译文 英文实用资料.docx
《单片机外文翻译汇编语言的艺术译文 英文实用资料.docx》由会员分享,可在线阅读,更多相关《单片机外文翻译汇编语言的艺术译文 英文实用资料.docx(13页珍藏版)》请在冰豆网上搜索。
单片机外文翻译汇编语言的艺术译文英文实用资料
TheArtofAssemblyLanguage
1.What'sWrongWithAssemblyLanguage?
2.What'sRightWithAssemblyLanguage?
1.What'sWrongWithAssemblyLanguage
Assemblylanguagehasaprettybadreputation.Thecommonimpressionaboutassemblylanguage
programmerstodayisthattheyareallhackersormisguidedindividualswhoneedenlightenment.
Herearethereasonspeoplegivefornotusingassembly:
(1)Assemblyishardtolearn.
(2)Assemblyishardtoreadandunderstand.
(3)Assemblyishardtodebug.
(4)Assemblyishardtomaintain.
(5)Assemblyishardtowrite.
(6)Assemblylanguageprogrammingistimeconsuming.
(7)Improvedcompilertechnologyhaseliminatedtheneedforassemblylanguage.
(8)Today,machinesaresofastthatwenolongerneedtouseassembly.
(9)Ifyouneedmorespeed,youshoulduseabetteralgorithmratherthanswitchtoassemblylanguage.
(10)Machineshavesomuchmemorytoday,savingspaceusingassemblyisnotimportant.
(11)Assemblylanguageisnotportable.
Thesearesomestrongstatementsindeed!
Giventhatthisisabookwhichteachesassemblylanguageprogramming,writtenforcollegelevelstudents,writtenbysomeonewhoappearstoknowwhathe'stalkingabout,yournaturaltendencyistobelievesomethingifitappearsinprint.Havingjustreadtheabove,you'restartingtoassumethatassemblymustbeprettybad.Andthat,dearfriend,iseightypercentofwhat'swrongwithassemblylanguage.Thatis,peopledevelopsomeverystrongmisconceptionsaboutassemblylanguagebasedonwhatthey'veheardfromfriends,instructors,articles,andbooks.Oh,assemblylanguageiscertainlynotperfect.Itdoeshavemanyrealfaults.Thosefaults,however,areblowncompletelyoutofproportionbythoseunfamiliarwithassemblylanguage.Thenexttimesomeonestartspreachingabouttheevilsofassemblylanguage,ask,"howmanyyearsofassemblylanguageprogrammingexperiencedoyouhave?
"Ofcourseassemblyishardtounderstandifyoudon'tknowit.Itissurprisinghowmanypeoplearewillingtospeakoutagainstassemblylanguagebasedonlyonconversationsthey'vehadorarticlesthey'veread.
Assemblylanguageusersalsousehighlevellanguages(HLLs);assembly'smostoutspokenopponentsrarelyuseanythingbutHLLs.Whowouldyoubelieve,anexpertwellversedinbothtypesofprogramminglanguagesorsomeonewhohasnevertakenthetimetolearnassemblylanguageanddevelopanhonestopinionofitscapabilities?
Inaconversationwithsomeone,Iwouldgotogreatlengthstoaddresseachoftheaboveissues.Indeed,inaroughdraftofthischapterIspentabouttenpagesexplainingwhatiswrongwitheachoftheabovestatements.However,thisbookislongenoughandIfeltthatverylittlewasgained
bygoingonandonaboutthesepoints.Nonetheless,abriefrebuttaltoeachoftheabovepointsisinorder,iffornootherreasonthantokeepyoufromthinkingthereisn'tadecentdefenseforthesestatements.
Assemblyishardtolearn.Soisanylanguageyoudon'talreadyknow.Trylearning(reallylearning)APL,Prolog,orSmalltalksometime.OnceyoulearnPascal,learninganotherlanguagelikeC,BASIC,FORTRAN,Modula-2,orAdaisfairlyeasybecausetheselanguagesarequitesimilartoPascal.Ontheotherhand,learningadissimilarlanguagelikePrologisnotsosimple.AssemblylanguageisalsoquitedifferentfromPascal.ItwillbealittlehardertolearnthanoneoftheotherPascal-likelanguages.However,learningassemblyisn'tmuchmoredifficultthanlearningyourfirstprogramminglanguage.
Assemblyishardtoreadandunderstand.Itsureis,ifyoudon'tknowit.Mostpeoplewhomakethisstatementsimplydon'tknowassembly.Ofcourse,it'sveryeasytowriteimpossible-to-readassemblylanguageprograms.It'salsoquiteeasytowriteimpossible-to-readC,Prolog,andAPLprograms.Withexperience,youwillfindassemblyaseasytoreadasotherlanguages.
Assemblyishardtodebug.Sameargumentasabove.Ifyoudon'thavemuchexperiencedebuggingassemblylanguageprograms,it'sgoingtobehardtodebugthem.RememberwhatitwaslikefindingbugsinyourfirstPascal(orotherHLL)programs?
Anytimeyoulearnanewprogramminglanguageyou'llhaveproblemsdebuggingprogramsinthatlanguageuntilyougain
experience.
Assemblyishardtomaintain.Cprogramsarehardtomaintain.Indeed,programsarehardtomaintainperiod.Inexperiencedassemblylanguageprogrammerstendtowritehardtomaintainprograms.Writingmaintainableprogramsisn'tatalent.It'saskillyoudevelopthroughexperience.
Assemblylanguageishard.Thisstatementactuallyhasaringoftruthtoit.Forthelongesttimeassemblylanguageprogrammerswrotetheirprogramscompletelyfromscratch,often"re-inventingthewheel."HLLprogrammers,especiallyC,Ada,andModula-2programmers,havelongenjoyedthebenefitsofastandardlibrarypackagewhichsolvesmanycommonprogrammingproblems.Assemblylanguageprogrammers,ontheotherhand,havebeenknowntorewriteanintegeroutputroutineeverytimetheyneedone.Thisbookdoesnottakethatapproach.Instead,ittakesadvantageofsomeworkdoneattheUniversityofCalifornia,Riverside:
theUCRStandardLibraryfor80x86AssemblyLanguageProgrammers.ThesesubroutinessimplifyassemblylanguagejustastheCstandardlibraryaidsCprogrammers.ThelibrarysourcelistingsareavailableelectronicallyviaInternetandvariousothercommunicationservicesaswellasona
companiondiskette.
Assemblylanguageprogrammingistimeconsuming.Softwareengineersestimatethatdevelopersspendonlyaboutthirtypercentoftheirtimecodingasolutiontoaproblem.EvenifittooktwiceasmuchtimetowriteaprograminassemblyversussomeHLL,therewouldonlybeafifteenpercentdifferenceinthetotalprojectcompletiontime.Infact,goodassemblylanguageprogrammersdonotneedtwiceasmuchtimetoimplementsomethinginassemblylanguage.ItistrueusingaHLLwillsavesometime;however,thesavingsisinsufficienttocounterthebenefitsofusingassemblylanguage.
Improvedcompilertechnologyhaseliminatedtheneedforassemblylanguage.Thisisn'ttrueandprobablyneverwillbetrue.Optimizingcompilersaregettingbettereveryday.However,assemblylanguageprogrammersgetbetterperformancebywritingtheircodedifferentlythantheywouldiftheywereusingsomeHLL.IfassemblylanguageprogrammerswrotetheirprogramsinCandthentranslatedthemmanuallyintoassembly,agoodCcompilerwouldproduceequivalent,orevenbetter,code.Thosewhomakethisclaimaboutcompilertechnologyarecomparingtheir
hand-compiledcodeagainstthatproducedbyacompiler.Compilersdoamuchbetterjobofcompilingthanhumans.Thenagain,you'llnevercatchanassemblylanguageprogrammerwriting"CcodewithMOVinstructions."Afterall,that'swhyyouuseCcompilers.
Today,machinesaresofastthatwenolongerneedtouseassembly.Itisamazingthatpeoplewillspendlotsofmoneytobuyamachineslightlyfasterthantheonetheyown,buttheywon'tspendanyextratimewritingtheircodeinassemblysoitrunsfasteronthesamehardware.There
aremanyragingdebatesaboutthespeedofmachinesversusthespeedofthesoftware,butonefactremains:
usersalwayswantmorespeed.Onanygivenmachine,thefastestpossibleprogramswillbewritteninassemblylanguage.
Ifyouneedmorespeed,youshoulduseabetteralgorithmratherthanswitchtoassemblylanguage.Whycan'tyouusethisbetteralgorithminassemblylanguage?
Whatifyou'realreadyusingthebestalgorithmyoucanfindandit'sstilltooslow?
Thisisatotallybogusargument
againstassemblylanguage.AnyalgorithmyoucanimplementinaHLLyoucanimplementinassembly.Ontheotherhand,therearemanyalgorithmsyoucanimplementinassemblywhichyoucannotimplementinaHLL.
Assemblylanguageisnotportable.Thisisanundeniablefact.An80x86assemblylanguageprogramwrittenforanIBMPCwillnotrunonanAppleMacintosh.Indeed,assemblylanguageprogramswrittenfortheAppleMacintoshwillnotrunonanAmiga,eventhoughtheysharethesame680x0microprocessor.Ifyouneedtorunyourprogramondifferentmachines,you'llhavetothinklongandhardaboutusingassemblylanguage.UsingC(orsomeotherHLL)isnoguaranteethatyourprogramwillbeportable.CprogramswrittenfortheIBMPCwon'tcompileandrunonaMacintosh.Andeveniftheydid,mostMacownerswouldn'taccepttheresult.
Portabilityisprobablythebiggestcomplaintpeoplehaveagainstassemblylanguage.Theyrefusetouseassemblybecauseitisnotportable,andthentheyturnaroundandwriteequallynon-portableprogramsinC.
Yes,therearelotsoflies,misconceptions,myths,andhalf-truthsconcerningassemblylanguage.Whateveryoudo,makesureyoulearnassemblylanguagebeforeformingyourownopinions.Speakingoutinignorancemayimpressotherswhoknowlessthanyoudo,butitwon'timpressthosewhoknowthetruth.
2What'sRightWithAssemblyLanguage?
Anoldjokegoessomethinglikethis:
"Therearethreereasonsforusingassemblylanguage:
speed,
speed,andmorespeed."Eventhosewhoabsolutelyhateassemblylanguagewilladmitthatif
speedisyourprimaryconcern,assemblylanguageisthewaytogo.Assemblylanguagehasseveralbenefits:
(1)Speed.Assemblylanguageprogramsaregenerallythefastestprogramsaround.
(2)Space.Assemblylanguageprogramsareoftenthesmallest.
(3)Capability.YoucandothingsinassemblywhicharedifficultorimpossibleinHLLs.
(4)Knowledge.Yourknowledgeofassemblylanguagewillhelpyouwritebetterprograms,evenwhenusingHLLs.
Assemblylanguageistheuncontestedspeedchampionamong