You are on page 1of 8

TheAssemblyLanguageLevel

THEASSEMBLYLANGUAGE LEVEL
AdrianCrciun
acraciun@ieat.ro

TheAssemblyLanguageLevel Introduction

theassemblylanguagelevelisimplementedbytranslation,andnotbyinterpretation (liketheunderlyinglevel); thesourceistheassemblylanguageprogram(sequenceoftextstatements); thetargetisthemachinelanguage,eachstatementbeingtranslatedintoonemachine instruction,andanobjectfileisgenerated; thetranslatoristheassembler,whichperformsthefollowingtasks: translatesymbolicinstructionnamesintonumericalinstructioncodes, translateregisternamesintoregisternumbers, translatesymbolicvariablenamesintonumericalmemorylocations;

anassemblylanguageprogrammerhasaccesstoallthefeaturesofthetargetmachine, suchasparitybitregisters,etc.;

TheAssemblyLanguageLevel WhyUseAssemblyLanguage?

assemblylanguageprogrammingistedious,complex,slow(assemblyprograms aredevelopedslowerbyaconsiderablefactorcomparedtohigherlanguage programs)andpronetoerrorwhyuseit?

performance: assemblylanguageprogramscanbeconsiderablyfasterthanhighlevel counterparts, theycanbemuchsmaller(goodforprogrammingembeddedapplications), theymakebetteruseoflimitedresources,

accesstothemachine: theassemblylanguagehascompleteaccesstothehardware, itcanimplementdevicecontrollers,handleOSinterrupts,etc.

TheAssemblyLanguageLevel TheFormatofAssemblyLanguageStatements
Example: I+J=N. (a)Pentium, (b)Motorola680x0 (c)(Utra)SPARC.

TheAssemblyLanguageLevel Pseudoinstructions

anassemblylanguageprogramcancontaininstructionstotheassembleritself pseudoinstructions(assemblerdirectives); examples:(MASMtheMicrosoftassemblerforIntel): SEGMENT,ENDSstart/endasegment, ALIGNcontrolthealignmentofthedata, EQUgiveasymbolicnametoanexpression, DWallocatestoragefor32bitwords, IF,ELSE,ENDIFconditionalassembly: WORDSIZEEQU16 IFWORDSIZEGT16 WSIZE:DW32 ELSE WSIZE:DW16 ENDIF.

TheAssemblyLanguageLevel Macros amacroisanameforacodesegment,thatcanbeusedoverandoveragain: amacrodefinitiongivesanametothepieceofcode, amacrocallinsertsthemacrointothecode, macroscanbeparametrized; example: SWAP MACROP1,P2 ;P1andP2areinterchanged MOVEAX,P1 ;EAX:=P1 MOVEBX,P2 ;EBX:=P2 MOVP2,EAX ;P2:=EAX MOVP1,EBX ;P1:=EBX ENDM

SWAPP,Q SWAPR,S

theuseofmacroseliminatestheoverheadofprocedurecalls;

TheAssemblyLanguageLevel TheAssemblyProcess thenaturalwaytoprocessassemblylanguageprogramisfortheassemblerto readoneinstructionandtranslateitintoamachineinstruction thisleadstoproblemswithconditionaljumpinstructions(forwardreferences), solution:twopassassemblers: passone:collectsymbolinformation(labels),intothesymboltable, passtwo:eachstatementisread,assembled,output: informationhastobeprovidedtothelinker,forlinkingupprocedures; thesymboltablecanbeorganizedinvariouswaystoallowfastretrieval: arrayofpairs, sortedarray, hashcoding; inreallife,mostprogramsconsistofmorethanoneprocedure: theproceduremustbelinkedtogether(bythelinker), thecompletetranslationofasourceprogramrequirestwosteps: compilationorassemblyofthesourceprocedures, linkingoftheobjectmodules;

TheAssemblyLanguageLevel LinkingandLoading

eachobjectmodulecontains:entrypointtable(listofsymbols),externalreference table(listofexternalsymbolsused),relocationdictionary(addressesintheprogram thatneedtoberelocated), thelinkermust(1)collectthetableofmodules,(2)assignstartaddressestomodules, (3)findallmemoryinstructionsand(4)procedurecallinstructions,tolinearizethe program(withrespecttomemorylocations); dynamiclinkingoccursduringexecution: modulesmaybeusedbymultipleprocesses, implementationinmodernOSs: DLL(DynamicLinkLibrary)Windows sharedlibrary(UNIX); theuseofdynamiclinkingreducesthesizeofprogramfiles;

You might also like