Hi, How can a write a inline function ? Thanks Michael !
When used with the extended in-line assembler the Keil C16x/ST10 C Compiler allows you to create in-line functions that generate the same efficient code as intrinsic functions.
1 typedef unsigned char BYTE; 2 typedef unsigned int WORD; 3 4 typedef struct cla { 5 unsigned char type; 6 unsigned char mode; 7 struct cla *p[2]; 8 } CLA; 9 10 CLA cl1; 11 BYTE type, mode; 12 CLA *pL, *pR; 13 int it; 14 15 __inline int Getit (CLA *pthis) { 16 1 int n1; 17 1 if (pthis->mode == 2) { 18 2 n1 = pthis->p[0]->mode | pthis->p[1]->mode; 19 2 } 20 1 else { 21 2 n1 = pthis->p[0]->type & pthis->p[1]->type; 22 2 } 23 1 return (n1); 24 1 } 25 26 __inline BYTE GetMode (CLA *pthis) { 27 1 return (pthis->mode & 0x0F); 28 1 } 29 __inline BYTE GetType (CLA *pthis) { 30 1 return (pthis->type & 0x08); 31 1 } 32 __inline CLA *GetNodeL (CLA *pthis) { 33 1 return (pthis->p[0]); 34 1 } 35 __inline CLA *GetNodeR (CLA *pthis) { 36 1 return (pthis->p[1]); 37 1 } 38 39 int near iLocal; 40 41 __inline WORD Mul2 (WORD w) { 42 1 if (w >= 0x10) { 43 2 __asm { 44 2 MOV R4,w 45 2 al1: MOV R5,iLocal 46 2 ADD R4,R5 47 2 mov w,R4 48 2 } 49 2 } else w <<= 10; 50 1 return (w); 51 1 } 52 53 54 void main (void) { 55 1 CLA *p1; 56 1 57 1 it = Mul2 (cl1.mode); 58 1 p1 = &cl1; 59 1 type = GetMode (p1); 60 1 mode = GetType (p1); 61 1 pL = GetNodeL (p1); 62 1 pR = GetNodeR (p1); 63 1 it = Getit (&cl1); 64 1 }