单片机外文翻译汇编语言的艺术.docx
- 文档编号:10766958
- 上传时间:2023-02-22
- 格式:DOCX
- 页数:13
- 大小:25.06KB
单片机外文翻译汇编语言的艺术.docx
《单片机外文翻译汇编语言的艺术.docx》由会员分享,可在线阅读,更多相关《单片机外文翻译汇编语言的艺术.docx(13页珍藏版)》请在冰豆网上搜索。
单片机外文翻译汇编语言的艺术
中文4557字
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.
Assemblylanguageistheuncontestedspeedchampionamongpr
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 单片机 外文 翻译 汇编语言 艺术