您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 公司方案 > 单片机飞思卡尔微处理器和指令集
1第四章微处理器结构和指令集MCUStructureTheCPURegistersfileInstructionlatch/decode/branchStack/heapInterrupt/context/VectortableClock/ResetMemoryperipheral2TheCPUcontains:ExecutionUnits(执行单元)Registerfile(寄存器堆)ControlUnit(控制单元)CPU–thecoreofmicrocontroller3微处理器存储空间:寄存器、RAM和ROM4.1微处理器的内部寄存器结构48-BitAccumulatorsAandBIndexRegisterXIndexRegisterYStackPointerProgramCounterConditionCodesRegisterCCRor16-BitDoubleAccumulatorDSXHINZVC707715000000015151515PCSPYXDBA70EPAGE*70RPAGE*70PPAGE*60GPAGE*00000IPL16bitMCURegisterfile(11,12,S12)5Carry/Borrow(FromMSB)OverflowZeroNegative(MSB=1)ConditionCodesRegisterCCRSXHINZVC70I-InterruptMaskHalfCarry(ForBCD)X-InterruptMaskSTOPDisable00000IPLInterruptprioritylevelIPLCCR6789一、指令和指令格式指令:CPU执行某种操作的命令。•指令系统:全部指令的集合。•计算机是靠机器指令加工处理信息的。•汇编语言:用助记符、符号和数字等来表示的程序语言。容易理解和记忆,它与机器语言一一对应。4.2S12汇编指令集10汇编:将用汇编语言编写的源程序翻译成机器语言程序(目标程序)的过程。完成汇编任务的程序叫做汇编程序。实际应用中,一般都用单片机在线仿真器(开发系统)来调试软件和硬件,调试成功后再用编程器将程序写入程序存储器中。在线仿真器通过串行口与通用系统微机通信,单片机的程序设计借助于微机实现。微机仿真器(开发系统)目标电路板单片机串行口11汇编语言与CPU的硬件结构紧密相关,不同的CPU其汇编语言是不同的,程序不能移植,使用不便。高级语言:与计算机的硬件结构没多大关系。程序通用性好,便于移植。如:C语言、BASIC语言。虽然应用程序可以主要用C语言来开发,但与时序相关的硬件操作必须用汇编语言编写。124.3指令按功能分类按功能可分为下列3类:•数据传送类•算术与逻辑运算类•控制转移类13[标号:]操作助记符[第一操作数][,第二操作数][,第三操作数][,第四操作数][;注释]操作助记符:以符号形式给出该指令执行什么操作。由2~5个英文字母表示。操作数:参与操作的数据或数据存放的地址。[]可选。*要养成直接以英语读操作助记符、直接记英语含义的习惯。如CLR读作clearLDAA读作loadaccumulatorA汇编指令格式14数据空间分为寄存器和存储器。寄存器:A,B,CCR,D,X,Y,SP存储器:对MC9S12XS128为$2000~$3FFF空间。可用_asm或asm做测试,双击修改数据内容4.3.1数据传送指令15Load指令,读到寄存器中来。如LDAA#$41;#立即数,$16进制LDAA读作LoadAccumulatorALDABLoadB(M)→BLDDLoadD(M:M+1)→(A:B)LDSLoadSP(M:M+1)→(SPH:SPL)LDXLoadindexregisterXLDYLoadindexregisterYLEASLoadEffectiveAddressintoSPLEAXLoadEffectiveAddressintoXLEAYLoadEffectiveAddressintoY16Store指令,写到寄存器中去。如STAA$2000;(A)→($2000)STAAStoreA(A)→MSTABStoreBSTDStoreDSTSStoreSPSTXStoreXSTYStoreYStore指令17Store指令,不经过寄存器的直接存储器数据传送指令。写到寄存器中去。如MOVB$2000,$2008;($2000)→($2008)MOVBMoveByteMOVWMoveWordMove指令18寄存器到寄存器的数据传送指令。如MOVB$2000,$2008;($2000)→($2008)TABTransferAtoB(A)→BTBATransferBtoATAPTransferAtoCCRTPATransferCCRtoATransfer指令19TFRTransferregistertoregisterTSXTransferSPtoXTSYTransferSPtoYTXSTransferXtoSPTYSTransferYtoSP20EXGExchangeregistertoregisterXGDXExchangeDwithYXGDYExchangeDwithYExchange指令21PSHAPushA(SP)-1→SP,(A)→(SP)PSHBPushBPSHCPushCCRPSHCWPushCCRH:CCRPSHDPushDPSHXPushXPSHYPushY堆栈操作指令22PULAPullA(M(SP))→A,(SP)+1→SPPULBPullBPULCPullCCRPULCWPullCCRH:CCRPULDPullDPULXPullXPULYPullY堆栈操作指令23SEXSignExtendBytetoWord把8位数转成16位数的符号扩展指令4.3.2算术与逻辑运算指令24ADDAADDwithoutcarrytoA(A)+(M)→AADDBADDwithoutcarrytoBADDDADDwithoutcarrytoD(A:B)+(M:M+1)→A:BADDXADDwithoutcarrytoX(X)+(M:M+1)→XADDYADDwithoutcarrytoY加、减法指令25ADCAADDwithcarrytoA(A)+(M)+C→AADCBADDwithcarrytoBADEDADDwithcarrytoDADEXADDwithcarrytoXADEYADDwithcarrytoY加、减法指令26SUCASubtractwithborrowfromA(A)-(M)-C→ASUCBSubtractwithborrowfromBSUEDSubtractwithborrowfromDSUEXSubtractwithborrowfromXSUEYSubtractwithborrowfromY加、减法指令27SUBASubtractmemoryfromA(A)-(M)→ASUBBSubtractmemoryfromBSUBDSubtractmemoryfromDSUBXSubtractmemoryfromXSUBYSubtractmemoryfromYABAAddAtoBSBASubtractBfromAABXAddBtoXABYAddBtoY加、减法指令28EMULMultiply(unsigned)16by16(D)×(Y)→Y:DEMULSMultiply(signed)16by16(D)×(Y)→Y:DMULMultiply(unsigned)8by8(A)×(B)→A:B乘除法指令29EDIVDivide(unsigned)32by16(Y:D)÷(X)→Y,Remained→DEDIVSDivide(signed)32by16(Y:D)÷(X)→Y,Remained→DFDIVFractionalDivide(unsigned)16by16(D)÷(X)→X,Remained→DIDIVIntegerDivide(unsigned)16by16(D)÷(X)→X,Remained→DIDIVSIntegerDivide(signed)16by16(D)÷(X)→X,Remained→D乘除法指令30EMACSMultiplyandAccumulate(signed)((M(X):M(X+1))×(M(Y):M(Y+1)))+(M~M+3)→M~M+3查表、插值指令TBLTableLookupandinterpolate8-bit(M)+[(B)×((M+1)-(M))]→AETBLTableLookupandinterpolate16-bit(M:M+1)+[(B)×((M+2:M+3)-(M:M+1))]→D乘加除法指令31DAADecimalAdjust(A)10十进制调整的BCD指令32INCIncrementmemory(M)+$01→MINCAIncrementA(A)+$01→MINCBIncrementB(B)+$01→MINCWIncrementmemory(M:M+1)+$0001→M:M+1INSIncrementSP(SP)+$0001→SPINXIncrementX(X)+$01→XINYIncrementY(Y)+$01→Y加一减一指令33DECDecrementmemory(M)-$01→MDECADecrementA(A)-$01→MDECBDecrementB(B)-$01→MDECWDecrementmemory(M:M+1)-$0001→M:M+1DESDecrementSP(SP)-$0001→SPDEXDecrementX(X)-$01→XDEYDecrementY(Y)-$01→Y加一减一指令34CLCClearCbitinCCR0→CCLIClearIbitinCCR0→ICLVClearVbitinCCR0→VCLRClearmemory$0→MCLRAClearA$0→MCLRBClearB$0→MCLRWClearmemory2bytes$00→M:M+1CLRXClearX2bytes$00→XCLRYClearY2bytes$00→Y清零指令35COMComplementmemory,1byte$FF-(M)→Mor(/M)→MCOMAComplementA,1byte$FF-(A)→Aor(/A)→ACOMBComplementB,1byte$FF-(B)→Bor(/B)→BCOMWComplementmemory,2bytes$FFFF-(M:M+1)→M:M+1COMXComplementX,2bytes$FFFF-(X)→XCOMYComplementY,2bytes$FFFF-(Y)→Y求反指令36NEGComplementmemory,1byte$00-(M)→Mor(/M)+1→MNEGAComplementA$00-(A)→Aor(/A)+1→ANEGBComplementB$00-(B)→Bor(/B)+1→BNEGWComplementmemory,2bytes$0000-(M:M+1)→M:M+1NEGXComplementX,2bytes$0000-(X)→XNEGYComplementY,2bytes$0000-(Y)→Y取负数指令37CBACompareAtoB(A)-(B)影响CCR寄存器CMPACompareAtomemory(A)-(M)CMPBCompareBtomemory(A)-(M)CPDCompareDtomemory(A:B)-(M:M+1)CPSCompareSPtomemory(SP)-(M:M+1)CPXCompareXtomemory(X)-(M:M+1)CPYCompareYtomemory(Y)-(M:M+1)比较指令38CPEDCompareDtomemorywithborrow(A:B)-(M:M+1)-CCPESCompareSPtom
本文标题:单片机飞思卡尔微处理器和指令集
链接地址:https://www.777doc.com/doc-3212493 .html