资源描述:
《微机原理ch03assemblylanguageprogramming》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、3ASSEMBLYLANGUAGEPROGRAMMING3.1DIRECTIVESANDSAMPLEPROGRAMAgivenassemblylanguageprogramisaseriesofstatements,orlines,whichareeitherassemblylanguageinstructionssuchasMOVorADD,orstatementscalleddirectives.;THEFORMOFANASSEMBLYLANGUAGEPROGRAM;NOTE:USINGSIMPLIFIEDSEGMENTDEFINITION.modelsm
2、all.stack64.datadata1db52hdata2db29hsumdb?.codemainprocfar;thisistheprogramentrypointmovax,@data;loadthedatasegmentmovds,ax;assignvaluetoDSmoval,data1;getthefirstoperandmovbl,data2;getthesecondoperandaddal,bl;addtheoperandsmovsum,al;storetheresultinlocationSUMmovah,4ch;setuptoreturn
3、DOSint21hmainendpp1procfarp1endpp2procfarp2endpendmain;thisistheprogramexitpoint图31SimpleassemblylanguageprogramDirectives(alsocalledpseudo-instructions)givedirectionstotheassemblerabouthowitshouldtranslatetheassemblylanguageinstructionsintomachinecode.Anassemblylanguageinstruction
4、consistsoffourfields:[label:]mnemonic[operands][;comment]3-15Bracketsindicatethatthefieldisoptional.lThelabelfieldallowsprogramtorefertoalineofcodebyname.Thelabelfieldcannotexceed31characters.lLabelsfordirectivesdonotneedendwithacolon.lAlabelmustendwithacolonwhenitreferstoanopcodege
5、neratinginstruction;thecolonindicatestotheassemblerthatthisreferstocodewiththiscodesegment.lTheassemblylanguagemnemonic(instruction)andoperand(s)fieldstogetherperformtherealworkoftheprogramandaccomplishthetasksforwhichtheprogramwaswritten.Inassemblylanguagesuchas:addal,blmovax,6764A
6、DDandMOVarethemnemonicopcodes,and“al,bl”and“ax,6764”aretheoperands.Thesetwofieldscouldcontainassemblerpseudo-instructions,ordirectives.Theyareusedbytheassemblertoorganizetheprogramaswellasotheroutputfiles.Directivesdonotgenerateanymachinecodeandareusedonlybytheassembler,suchasDB,END
7、.lThecommentfieldbeginswitha“;”theassemblerignorescomments3.1.1ModeldefinitionThefirststatementin图31afterthecommentsistheMODELdirective.Thisdirectiveselectsthesizeofthememorymodel.Amongtheoptionsforthememorymodelare:.modelsmall;thisdirectivedefinesthemodeassmallSMALLisoneofthemostw
8、idelyusedmemorymode