主函数中调用: Msg_Register(InkeyTest_MsgProc, Msg_Key0,Msg_Key1);//InkeyTest_MsgProc是Msg处理函数
//--------------------------------------------- //消息处理程序的登记 //入口:消息字,函数指针 //开始消息字和结束消息字之间的处理函数指针设置 //--------------------------------------------- void Msg_Register(void(* Function)(), const unsigned char mEnumMin, const unsigned char mEnumMax) { unsigned char min=mEnumMin; unsigned char max=mEnumMax; unsigned char i; while(min<=max) { sInMsg.aMessage_Function[min++]=Function; } } 上面的子函数汇编后是这样的: void Msg_Register(void(* Function)(), const unsigned char mEnumMin, const unsigned char mEnumMax) { 3F8427 Msg_Register: 3F8427 FE06 ADDB SP,#6 3F8428 9744 MOV *-SP[4],AH 3F8429 9643 MOV *-SP[3],AL 3F842A A842 MOVL *-SP[2],XAR4 unsigned char min=mEnumMin; 3F842B 9243 MOV AL,*-SP[3] 3F842C 9645 MOV *-SP[5],AL unsigned char max=mEnumMax; 3F842D 9244 MOV AL,*-SP[4] 3F842E 9646 MOV *-SP[6],AL unsigned char i; // for(i=min;i<=max;i++) while(min<=max) 3F842F 6F0C SB DW$L$_Msg_Register$2$E,UNC 3F843B DW$L$_Msg_Register$2$E: 3F843B 9246 MOV AL,*-SP[6] 3F843C 5445 CMP AL,*-SP[5] 3F843D 67F3 SB DW$L$_Msg_Register$2$B,HIS { sInMsg.aMessage_Function[min++]=Function; 3F8430 DW$L$_Msg_Register$2$B: 3F8430 761F MOVW DP,#0x0203 3F8432 9345 MOV AH,*-SP[5] 3F8433 C400 MOVL XAR6,@0 3F8434 0EA8 MOVU ACC,@AH 3F8435 0A45 INC *-SP[5] 3F8436 FF30 LSL ACC,1 3F8437 07A6 ADDL ACC,@XAR6 3F8438 8AA9 MOVL XAR4,@ACC 3F8439 C442 MOVL XAR6,*-SP[2] 3F843A C2C4 MOVL *+XAR4[0],XAR6 } } 3F843E DW$L$_Msg_Register$3$E: 3F843E FE86 SUBB SP,#6 3F843F 0006 LRETR //=============================================== 当min=3时进入循环体运行到3F843A C2C4 MOVL *+XAR4[0],XAR6处,栈里的min和max就改变了,min成了3f,max 成了838C(3f838c是XAR6寄存器的内容。)也就是将XAR6的数据移到*+XAR4[0],却改变了min和max的值。
百思不得其解。不知何故?
sInMsg结构体是这样的: struct InMsg{ void (**aMessage_Function)(); //对应消息字的函数指针数组开始指针 unsigned char *aMsgBufStart; //消息缓冲区开始 unsigned char *aMsgBufEnd; //消息缓冲区结束位置 unsigned char *pMsgIn; unsigned char *pMsgOut; unsigned char aReadMsgBuffer[5]; //用户使用的消息信息缓冲区,只读[0]消息字,[1]-[4]为参数 }; struct InMsg sInMsg; |