资源描述:
《单片机原理及应用--第4章 80c51单片机汇编语言程序设计》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、Chapter4ProgramDesignofAssembleLanguage主讲教师:黄英Contents:4.1IntroductionofAssembleLanguage24.1.1Features24.1.2Format24.2Basicstructures24.2.1Sequentialprogram24.2.2Branchingprogram34.2.2.1Singlebranchingprogram34.2.2.2.Multi-branchingprogram111.ByusingsomeCJNEinstructions112.Byusing“addresstable”13
2、3.Byusing“jumpinstructiontable”154.Byusingstackoperation184.2.3CircularStructure234.3DelaytimeProgram244.3.1Single-cycledelaytimeprogram244.3.2Longdelaytimeprogram(Multi-cycle)254.3.3Adjustingdelaytimerange254.3.4Getdifferenttimingwithbasicdelayprogram254.4Pseudoinstruction254.5Howtoeditandassemb
3、lethesourceprogram25第7页,共7页4.1IntroductionofAssembleLanguage4.1.1Features1.Producestheoptimizedprogram.2.Programmermustbefamiliarwithhardware.3.Manageandcontrolhardwaredirectly.4.Notuniversal,can’tbetransplanted.4.1.2Format(Detailedinformation:P77)[
4、uctures3types:²SequentialStructure²BranchingStructure²CircularStructure4.2.1SequentialprogramForexample:3-byteunsignedconstantsadditionAssumedthat:50H~52HcellsofinternalRAMhavethreeaugendsrespectively(beginningwithhighbytes),53H~55HcellsofinternalRAMhavethreeaddendsrespectively(beginningwithhighb
5、ytes).Requirement:Designaprogramtoputtheadditionresultinto50H~52Hcells(beginningwithhighbytes),andthecarrybitinto20Hbitofbitaddressablearea.DECR0(50H/51H/52H)=11H/22H/33HDECR1(53H/54H/55H)=77H/88H/99H③MOVA,@R0ADDCA,@R1112233HMOV@R0,A+778899HCLRAADDCA,#00H?④MOVR0,#20H?MOV@R0,A?MOVR0,#52HMOVR1,#55H
6、①MOVA,@R0ADDA,@R1MOV@R0,ADECR0DECR1②MOVA,@R0ADDCA,@R1MOV@R0,A4.2.2Branchingprogram4.2.2.1Singlebranchingprogram·Usingjumpinstructions:P67-68:JZ,JNZ,CJNE,DJNZ(条件转移指令)P73-74:JC,JNC,JB,JNB,JBC(位控制转移指令)第7页,共7页Forexample:ComparethevaluesAssumedthat:Therearethreecontinuouscells(ST1,ST2,ST3)intheexterna
7、lRAMwhereST1andST2have8-bitunsignedbinaryconstantsrespectively.Requirement:Designaprogramtofindthebiggerconstant,andputitintoST3cell.START:CLRC;clearthecarrybitMOVDPTR,#ST1;setthedatapointerMOVXA,@DPTRMOVR2,A;putthe1st