#include "main.h"
code pHotTaskFUNC pHotTaskTable[] = { TaskInit, Task1, Task2, Task3, };
void main() { unsigned char i; /*------------------------------------------------------ Keil C51中一个C函数被8种方法调用中一半可用变量调用 -------------------------------------------------------*/ for(i = 0; i <= 3; i ++) { /*------------------------------------------------------ 方法1.函数指针数组调用函数(C语言)(27个字节) C:0x0031 E508 MOV A,0x08 C:0x0033 75F003 MOV B(0xF0),#0x03 C:0x0036 A4 MUL AB C:0x0037 2448 ADD A,#0x48 C:0x0039 F582 MOV DPTR(0x82),A C:0x003B E4 CLR A C:0x003C 3405 ADDC A,#0x05 C:0x003E F583 MOV DPH(0x83),A C:0x0040 E4 CLR A C:0x0041 7401 MOV A,#0x01 C:0x0043 93 MOVC A,@A+DPTR C:0x0044 FA MOV R2,A C:0x0045 7402 MOV A,#0x02 C:0x0047 93 MOVC A,@A+DPTR C:0x0048 F9 MOV R1,A C:0x0049 12055C LCALL C?ICALL(C:055C) -------------------------------------------------------*/ pHotTaskTable();// /*------------------------------------------------------ 方法5.函数指针数组调用函数(C语言HotIns.h/c和COM接口)(18个字节) C:0x004C E508 MOV A,0x08 C:0x004E 75F003 MOV B(0xF0),#0x03 C:0x0051 A4 MUL AB C:0x0052 243F ADD A,#iHotTaskTable(0x3F) C:0x0054 F8 MOV R0,A C:0x0055 08 INC R0 C:0x0056 E6 MOV A,@R0 C:0x0057 FA MOV R2,A C:0x0058 08 INC R0 C:0x0059 E6 MOV A,@R0 C:0x005A F9 MOV R1,A C:0x005B 12055C LCALL C?ICALL(C:055C) -------------------------------------------------------*/ _icall_((void *)iHotTaskTable.pVtbl); /*------------------------------------------------------ 方法6.函数指针数组调用函数(C语言HotIns.h/c和COM接口)(23个字节) C:0x005E E508 MOV A,0x08 C:0x0060 75F003 MOV B(0xF0),#0x03 C:0x0063 A4 MUL AB C:0x0064 243F ADD A,#iHotTaskTable(0x3F) C:0x0066 F8 MOV R0,A C:0x0067 08 INC R0 C:0x0068 E6 MOV A,@R0 C:0x0069 FA MOV R2,A C:0x006A 08 INC R0 C:0x006B E6 MOV A,@R0 C:0x006C AE02 MOV R6,0x02 C:0x006E 8E83 MOV DPH(0x83),R6 C:0x0070 F582 MOV DPTR(0x82),A C:0x0072 120455 LCALL _reset_code__(C:0455) -------------------------------------------------------*/ _intjmp_((unsigned int)iHotTaskTable.pVtbl); /*------------------------------------------------------ 方法7.函数指针数组调用函数(COM接口函指针数组)(18个字节) C:0x0075 E508 MOV A,0x08 C:0x0077 75F003 MOV B(0xF0),#0x03 C:0x007A A4 MUL AB C:0x007B 243F ADD A,#iHotTaskTable(0x3F) C:0x007D F8 MOV R0,A C:0x007E 08 INC R0 C:0x007F E6 MOV A,@R0 C:0x0080 FA MOV R2,A C:0x0081 08 INC R0 C:0x0082 E6 MOV A,@R0 C:0x0083 F9 MOV R1,A C:0x0084 12055C LCALL C?ICALL(C:055C) -------------------------------------------------------*/ iHotTaskTable.pVtbl(); }
/*------------------------------------------------------ 方法1.函数指针数组调用函数(C语言) (20个字节) -------------------------------------------------------*/ pHotTaskTable[0]();//TaskInit pHotTaskTable[1]();//Task1 pHotTaskTable[2]();//Task2 pHotTaskTable[3]();//Task3 /*------------------------------------------------------ 方法2.直接地址调用函数(见菜农的HotIns.h/c)(3个字节) -------------------------------------------------------*/ _icall_((void *)TaskInit);//TaskInit _icall_((void *)Task1);//Task1 _icall_((void *)Task2);//Task2 _icall_((void *)Task3);//Task3 /*------------------------------------------------------ 方法3.间接地址调用函数(见菜农的HotIns.h/c) (11个字节) -------------------------------------------------------*/ _intjmp_(TaskInit);//TaskInit _intjmp_(Task1);//Task1 _intjmp_(Task2);//Task2 _intjmp_(Task3);//Task3 /*------------------------------------------------------ 方法4.函数名调用函数(C语言) (3个字节) -------------------------------------------------------*/ TaskInit();//TaskInit Task1();//Task1 Task2();//Task2 Task3();//Task3 /*------------------------------------------------------ 方法5.函数指针数组调用函数(C语言HotIns.h/c和COM接口)(15个字节) -------------------------------------------------------*/ _icall_((void *)iHotTaskTable.pVtbl[0]);//TaskInit _icall_((void *)iHotTaskTable.pVtbl[1]);//Task1 _icall_((void *)iHotTaskTable.pVtbl[2]);//Task2 _icall_((void *)iHotTaskTable.pVtbl[3]);//Task3 /*------------------------------------------------------ 方法6.函数指针数组调用函数(C语言HotIns.h/c和COM接口)(22个字节) -------------------------------------------------------*/ _intjmp_((unsigned int)iHotTaskTable.pVtbl[0]);//TaskInit _intjmp_((unsigned int)iHotTaskTable.pVtbl[1]);//Task1 _intjmp_((unsigned int)iHotTaskTable.pVtbl[2]);//Task2 _intjmp_((unsigned int)iHotTaskTable.pVtbl[3]);//Task3 /*------------------------------------------------------ 方法7.函数指针数组调用函数(COM接口函指针数组)(15个字节) -------------------------------------------------------*/ iHotTaskTable.pVtbl[0]();//TaskInit iHotTaskTable.pVtbl[1]();//Task1 iHotTaskTable.pVtbl[2]();//Task2 iHotTaskTable.pVtbl[3]();//Task3 /*------------------------------------------------------ 方法8.函数指针数组调用函数(COM接口函指针名)(15个字节) -------------------------------------------------------*/ iHotTaskTable.lpVtbl.TaskInit();//TaskInit iHotTaskTable.lpVtbl.Task1();//Task1 iHotTaskTable.lpVtbl.Task2();//Task2 iHotTaskTable.lpVtbl.Task3();//Task3 HotTaskStart(TaskInit);//装载根任务 }
|