单片机原理及应用--第4章 80c51单片机汇编语言程序设计_第1页
单片机原理及应用--第4章 80c51单片机汇编语言程序设计_第2页
单片机原理及应用--第4章 80c51单片机汇编语言程序设计_第3页
单片机原理及应用--第4章 80c51单片机汇编语言程序设计_第4页
单片机原理及应用--第4章 80c51单片机汇编语言程序设计_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

CHAPTER4PROGRAMDESIGNOFASSEMBLELANGUAGE主讲教师黄英CONTENTS41INTRODUCTIONOFASSEMBLELANGUAGE2411FEATURES2412FORMAT242BASICSTRUCTURES2421SEQUENTIALPROGRAM2422BRANCHINGPROGRAM34221SINGLEBRANCHINGPROGRAM34222MULTIBRANCHINGPROGRAM111BYUSINGSOMECJNEINSTRUCTIONS112BYUSING“ADDRESSTABLE”133BYUSING“JUMPINSTRUCTIONTABLE”154BYUSINGSTACKOPERATION18423CIRCULARSTRUCTURE2343DELAYTIMEPROGRAM24431SINGLECYCLEDELAYTIMEPROGRAM24432LONGDELAYTIMEPROGRAM(MULTICYCLE)25433ADJUSTINGDELAYTIMERANGE25434GETDIFFERENTTIMINGWITHBASICDELAYPROGRAM2544PSEUDOINSTRUCTION2545HOWTOEDITANDASSEMBLETHESOURCEPROGRAM2541INTRODUCTIONOFASSEMBLELANGUAGE411FEATURES1PRODUCESTHEOPTIMIZEDPROGRAM2PROGRAMMERMUSTBEFAMILIARWITHHARDWARE3MANAGEANDCONTROLHARDWAREDIRECTLY4NOTUNIVERSAL,CANTBETRANSPLANTED412FORMAT(DETAILEDINFORMATIONP77)42BASICSTRUCTURES3TYPESSEQUENTIALSTRUCTUREBRANCHINGSTRUCTURECIRCULARSTRUCTURE421SEQUENTIALPROGRAMFOREXAMPLE3BYTEUNSIGNEDCONSTANTSADDITION422BRANCHINGPROGRAM4221SINGLEBRANCHINGPROGRAMUSINGJUMPINSTRUCTIONSP6768JZ,JNZ,CJNE,DJNZ(条件转移指令)P7374JC,JNC,JB,JNB,JBC(位控制转移指令)ASSUMEDTHAT50H52HCELLSOFINTERNALRAMHAVETHREEAUGENDSRESPECTIVELY(BEGINNINGWITHHIGHBYTES),53H55HCELLSOFINTERNALRAMHAVETHREEADDENDSRESPECTIVELY(BEGINNINGWITHHIGHBYTES)REQUIREMENTDESIGNAPROGRAMTOPUTTHEADDITIONRESULTINTO50H52HCELLS(BEGINNINGWITHHIGHBYTES),ANDTHECARRYBITINTO20HBITOFBITADDRESSABLEAREAMOVR0,52HMOVR1,55HMOVA,R0ADDA,R1MOVR0,ADECR0DECR1MOVA,R0ADDCA,R1MOVR0,ADECR0(50H/51H/52H)11H/22H/33HDECR1(53H/54H/55H)77H/88H/99HMOVA,R0ADDCA,R1112233HMOVR0,A778899HCLRAADDCA,00HMOVR0,20HMOVR0,AFOREXAMPLECOMPARETHEVALUESSTARTCLRCCLEARTHECARRYBITMOVDPTR,ST1SETTHEDATAPOINTERMOVXA,DPTRMOVR2,APUTTHE1STCONSTANTINTOR2INCDPTRMOVXA,DPTRPUTTHE2STCONSTANTINTOASUBBA,R2AAR22ST1STJNCBIG1IFNOCARRY,THENTHE2STCONSTANTISBIGGERXCHA,R2ELSE1STCONSTANTISBIGGER,ANDPUTINTOABIG0INCDPTRLETDPTRPOINTSTOTHERESULTCELLMOVXDPTR,ASAVETHEBIGGERCONSTANTRETBIG1MOVXA,DPTRPUTTHE2STCONSTANTINTOASJMPBIG04222MULTIBRANCHINGPROGRAMINSTRUCTIONSETHASNOMULTIBRANCHINGINSTRUCTION4METHODSTOREALIZEMULTIBRANCHING1BYUSINGSOMECJNEINSTRUCTIONS2BYUSING“ADDRESSTABLE”3BYUSING“JUMPINSTRUCTIONTABLE”4BYUSINGSTACKOPERATION1BYUSINGSOMECJNEINSTRUCTIONSCJNEA,DATA,RELPUTTHEBRANCHINGNUMBERINTOAFOREXAMPLETEMPERATURECONTROLSYSTEMCJNEA,55H,LOOP1IFTAT55(UPPERVALUELIMIT),THENJUMPTOLOOP1AJMPFHTAT55,JUMPTOMAINPROGRAMFH(返回)LOOP1JNCJWIFCY0,TAT55,THENJUMPTOJW(降温)CJNEA,54H,LOOP2IFTAT54(LOWERVALUELIMIT),THENJUMPTOLOOP2AJMPFHTAT54,JUMPTOMAINPROGRAM(FH)LOOP2JCSWIFCY1,TAT55,THENEXECUTESTHETEMPERATUREDOWNPROCESSINGSUBPROGRAM(JW)IFTA(R1SAVESHIGH8BITADDRESS)ANLA,0FHFETCHLOW4BITFROMHIGHADDRESS,ANDCLEARHIGH4BITANLP2,0F0HFETCHHIGH4BITFROMP2PORT,ANDCLEARLOW4BITOFP2ORLP2,ANOTCHANGEHIGH4BITOFP2,ANDSENDLOW4BITOFP2MOVXA,R0FETCHDATAFROMEXTERNALRAM(4KB)TOA(R0SAVESLOW8BITADDRESS)SJMPDONESTOPBR3MOVDPL,R003PUTLOW8BITADDRESSOFEXTERNALRAMTODPLMOVDPH,R1PUTHIGH8BITADDRESSOFEXTERNALRAMTODPHMOVXA,DPTRFETCHDATAFROMEXTERNALRAM(64KB)TOADONESJMPSTOP3BYUSING“JUMPINSTRUCTIONTABLE”FOREXAMPLER300,01,02,03,MOVA,R3PUTTHEBRANCHINGNUMBERINTOARLAABRANCHINGNUMBER2MOVDPTR,BRTABLETDPTRPOINTTOBASEADDRESSOFOFFSETTABLEJMPADPTRJUMPTOTHECORRESPONDINGSUBROUTINE,PCADPTRBRTABAJMPROUT0JUMPTOROUT0AJMPROUT1JUMPTOROUT1AJMPROUT2JUMPTOROUT2AJMPROUT3JUMPTOROUT3AJMPROUTNJUMPTOROUTNWHY“RLA”WHENR300,NEEDJUMPTOBRTAB0,SOA00,WHENR301,NEEDJUMPTOBRTAB2,SOA02,WHENR302,NEEDJUMPTOBRTAB4,SOA04,WHENR303,NEEDJUMPTOBRTAB6,SOA06ASSUMEDTHATTHEREAREFOURBRANCHINGPROGRAMS,WHICHFUNCTIONISTOFETCHDATAFROMINTERNALRAM,EXTERNALRAM(LOWER256B),EXTERNALRAM(4KB),ANDEXTERNALRAM64KBRESPECTIVELYTOAR0SAVESLOW8BITADDRESS,R1SAVESHIGH8BITADDRESS,R3SAVESBRANCHINGNUMBERBRTABDENOTESTHEBASEADDRESSOFOFFSETTABLEBR0_BRTABBR3_BRTABDENOTEOFFSETREQUIREMENTDESIGNAPROGRAMTOREALIZEMULTIBRANCHINGASSUMEDTHATR3SAVESBRANCHINGNUMBERBRTABDENOTESTHEBASEADDRESSOFJUMPINSTRUCTIONTABLEREQUIREMENTDESIGNAPROGRAMTOREALIZEMULTIBRANCHINGOFFSETTABLE(OFFSETVALUEBR0/BR1/BR2/BR3BRTAB)JUMPINSTRUCTIONTABLE4BYUSINGSTACKOPERATIONSTEPS(1)PUTTHE16BITADDRESSINTOSTACK(2)USINGRETINSTRUCTIONTOGETPCVALUEFROMSTACKFOREXAMPLER300,01,02,03MOVDPTR,BRTABLETDPTRPOINTTOBASEADDRESSOFOFFSETTABLEMOVA,R3PUTTHEBRANCHINGNUMBERINTOARLAABRANCHINGNUMBER2MOVR1,AR12R3INCAA2R31MOVCA,ADPTRFETCHLOW8BITADDRESSTOAPUSHACCANDPUTLOW8BITADDRESSINTOSTACKMOVA,R1MOVCA,ADPTRFETCHHIGH8BITADDRESSTOAPUSHACCANDPUTITINTOSTACKRETSETPCVALUEFROMSTACKGETHIGH8BITADDRESSFIRST,ANDTHENLOW8BITADDRESSBRTABDWBR016BITADDRESSOFBRANCHINGSUBROUTINE0DWBR116BITADDRESSOFBRANCHINGSUBROUTINE1DWBR216BITADDRESSOFBRANCHINGSUBROUTINE2DWBR316BITADDRESSOFBRANCHINGSUBROUTINE3DWBRN16BITADDRESSOFBRANCHINGSUBROUTINENNOTEBRTAB3000H16BITADDRESSR3R1RLAINCA3000HIGH8BITADDRESS3001LOW8BITADDRESSBR00013002HIGH8BITADDRESS3003LOW8BITADDRESSBR11233004HIGH8BITADDRESS3005LOW8BITADDRESSBR22453006HIGH8BITADDRESS3007LOW8BITADDRESSBR3367RETPC158SP,SPSP1PC70SP,SPSP1PUSHDIRECTSPSP1,(SP)(DIRECT)SONEEDTOPUSHLOW8BITADDRESSFIRST,ANDTHENPUSHHIGH8BITADDRESSATLAST423CIRCULARSTRUCTUREMETHODUSINGCONDITIONALJUMPINSTRUCTIONSFOREXAMPLEMOVR2,0FFHSETTHEINITIALVALUEOFTHELENGTHCOUNTERMOVR0,3FHSETTHEINITIALVALUEOFTHESTRINGPOINTERLOOPINCR2R200H,01H,INCR0R040H,41H,CJNER0,0DH,LOOPRETASSUMEDTHATR3SAVESBRANCHINGNUMBERBRTABDENOTESTHEBASEADDRESSOFJUMPINSTRUCTIONTABLEREQUIREMENTDESIGNAPROGRAMTOREALIZEMULTIBRANCHINGASSUMEDTHATTHEREISACHARACTERSTRINGTHATADOPTS“ENTER”SYMBOLASTHEENDINGFLAGTHISSTRINGISSAVEDINTHEINTERNALRAMBEGINNINGWITH40HCELLREQUIREMENTDESIGNAPROGRAMTOGETTHELENGTHOFTHISSTRING16BITADDRESSTABLEPAYATTENTIONTOTHEOPERATIONOFDW43DELAYTIMEPROGRAM431SINGLECYCLEDELAYTIMEPROGRAMMOVR5,TIME1LOOPNOP1NOP1DJNZR5,LOOP2IFFOSC6MHZ,THENMACHINECYCLETMSOTOTALDELAYTIMETMAX1(112)2USTIMETIME00HFFH,0255,CYCLES265TIMES1(112)2US256120482049US432LONGDELAYTIMEPROGRAM(MULTICYCLE)MOVR5,TIME11LOOP2MOVR4,TIME21LOOP1NOP1NOP1DJNZR4,LOOP12DJNZR5,LOOP22RET2IFFOSC6MHZ,THENTOTALDELAYTIMETMAXTMAX1(1(112)2562)256)2)2US1525828525829US433ADJUSTINGDELAYTIMERANGEBYADDINGORDELETINGINSTRUCTIONSTHATDONTAFFECTPROGRAMFUNCTIONMOVR0,TIME1LOOPADDA,R11INCDPTR2DJNZR0,LOOP2I

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论