资源描述:
《Assembly Language, The True Language Of Programmers》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、1.AssemblyLanguage:TheTrueLanguageOfProgrammersAssemblyPCPCLanguage:TheundergroundTrueLanguageOfProgrammersChapter1Therearemanyhigh-level,structuredlanguagesforprogrammingtoday'sPCs.TwopopularexamplesareC++andPascal.However,assemblylanguagestillhasitsplaceintoday'sprogrammingworld.Sinceitmimi
2、cstheoperationsoftheCPUatthemachinelevel,assemblylanguageletsyougetrighttothe"heart"ofyourPC.Infact,therearesometasksthatyoucandoonlybyusingassemblylanguage.Whileit'struethatthePascallanguageiscapableenoughtohandleinterrupts,itcan'tbeusedtopasskeyboardinputtoDOS,forexample.SincePascalhasnonat
3、ivewaytodothis,youmuststillinsertanassemblermoduleroutinetoperformthefunction.Likewise,youcan'teasilyremoveahigh-levelresidentprogramfrommemory.Onceagain,youhavetowritetheroutineinassemblylanguagetodothis.Formanyapplications,programmingcodemuststillbeascompactaspossible.Forexample,inprogrammi
4、ngresidentprograms,eachkilobyteofRAMbelowthe640Kboundaryisvital.Programswritteninhigh-levellanguagesusuallyrequirearuntimelibrarywhichmayaddseveraladditionalkilobytestothesize.Assemblylanguageprogramsdon'tneedthesebulkylibraryroutines.However,themostimportantadvantageofassemblylanguageisspeed
5、.Althoughhigh-levellanguagescanbeoptimizedforspeedofexecution,eventhebestoptimizationcannotreplacetheexperienceofaprogrammer.Here'sasimpleexample.Let'ssaythatyouwanttoinitializetwovariablesinPascaltoazerovalue.Thecompilerwillgeneratethefollowingassemblycode:xorax,axmovvar1,axxorax,axmovvar2,a
6、xHere,thePascalcompileroptimizedtheexecutionspeedbyusingtheXORinstructiontozerotheaxregister(thefastestwaytodothis)andstoringthisvalueasvar1.However,duetocompiler'slimitations,theAXregisterwasagainzeroedbeforethesecondassignmentalthoughthiswasredundant.Fortrulytime-criticaltaskssuchasspritemo
7、vementandhigh-speedgraphics,theonlychoicemaybetouseassemblylanguage.Therearetwobasicwaystodothis:1.UseaninternalassemblersuchastheonebuiltintoBorlandPascalanditsasmdirective.2.Useastand-aloneassemblersuchasTurboAssemblerorMicrosoftAssembler.E