2011年(29)
分类:
2011-05-08 01:43:56
printf ( "I love you" ); printf ( "%d", a ); printf ( "%d,%d", a, b ); |
int printf ( const char *format, ... ); |
void va_start ( va_list arg_ptr, prev_param ); /* ANSI version */ type va_arg ( va_list arg_ptr, type ); void va_end ( va_list arg_ptr ); |
#define va_start ( ap, v ) ( ap = (va_list)&v + _INTSIZEOF(v) ) |
#define _INTSIZEOF(n) ((sizeof ( n ) + sizeof ( int ) - 1 ) & ~( sizeof( int ) - 1 ) ) |
#define va_arg(list, mode) ((mode *)(list =\ (char *) ((((int)list + (__builtin_alignof(mode)<=4?3:7)) &\ (__builtin_alignof(mode)<=4?-4:-8))+sizeof(mode))))[-1] |
#define va_end ( list ) |
#include /* 函数名:max * 功能:返回n个整数中的最大值 * 参数:num:整数的个数 ...:num个输入的整数 * 返回值:求得的最大整数 */ int max ( int num, ... ) { int m = -0x7FFFFFFF; /* 32系统中最小的整数 */ va_list ap; va_start ( ap, num ); for ( int i= 0; i< num; i++ ) { int t = va_arg (ap, int); if ( t > m ) { m = t; } } va_end (ap); return m; } /* 主函数调用max */ int main ( int argc, char* argv[] ) { int n = max ( 5, 5, 6 ,3 ,8 ,5); /* 求5个整数中的最大值 */ cout << n; return 0; } |
/////////////////////////////////////////////////////////////////////////////// // 函数名称: DrawText // 功能说明: 在显示屏上绘制文字 // 参数说明: xPos ---横坐标的位置 [0 .. 30] // yPos ---纵坐标的位置 [0 .. 64] // ... 可以同数字一起显示,需设置标志(%d、%l、%x、%s) /////////////////////////////////////////////////////////////////////////////// extern void DrawText ( BYTE xPos, BYTE yPos, LPBYTE lpStr, ... ) { BYTE lpData[100]; //缓冲区 BYTE byIndex; BYTE byLen; DWORD dwTemp; WORD wTemp; int i; va_list lpParam; memset( lpData, 0, 100); byLen = strlen( lpStr ); byIndex = 0; va_start ( lpParam, lpStr ); for ( i = 0; i < byLen; i++ ) { if( lpStr[i] != ’%’ ) //不是格式符开始 { lpData[byIndex++] = lpStr[i]; } else { switch (lpStr[i+1]) { //整型 case ’d’: case ’D’: wTemp = va_arg ( lpParam, int ); byIndex += IntToStr( lpData+byIndex, (DWORD)wTemp ); i++; break; //长整型 case ’l’: case ’L’: dwTemp = va_arg ( lpParam, long ); byIndex += IntToStr ( lpData+byIndex, (DWORD)dwTemp ); i++; break; //16进制(长整型) case ’x’: case ’X’: dwTemp = va_arg ( lpParam, long ); byIndex += HexToStr ( lpData+byIndex, (DWORD)dwTemp ); i++; break; default: lpData[byIndex++] = lpStr[i]; break; } } } va_end ( lpParam ); lpData[byIndex] = ’\0’; DisplayString ( xPos, yPos, lpData, TRUE); //在屏幕上显示字符串lpData } |
//显示字符串 showString ( BYTE xPos, BYTE yPos, LPBYTE lpStr ) //显示数字 showNum ( BYTE xPos, BYTE yPos, int num ) //以16进制方式显示数字 showHexNum ( BYTE xPos, BYTE yPos, int num ) |
1. 004010C8 push 5 2. 004010CA push 8 3. 004010CC push 3 4. 004010CE push 6 5. 004010D0 push 5 6. 004010D2 push 5 7. 004010D4 call @ILT+5(max) (0040100a) |
int max ( int num, ...) { 1. 00401020 push ebp 2. 00401021 mov ebp,esp 3. 00401023 sub esp,50h 4. 00401026 push ebx 5. 00401027 push esi 6. 00401028 push edi 7. 00401029 lea edi,[ebp-50h] 8. 0040102C mov ecx,14h 9. 00401031 mov eax,0CCCCCCCCh 10. 00401036 rep stos dword ptr [edi] va_list ap; int m = -0x7FFFFFFF; /* 32系统中最小的整数 */ 11. 00401038 mov dword ptr [ebp-8],80000001h va_start ( ap, num ); 12. 0040103F lea eax,[ebp+0Ch] 13. 00401042 mov dword ptr [ebp-4],eax for ( int i= 0; i< num; i++ ) 14. 00401045 mov dword ptr [ebp-0Ch],0 15. 0040104C jmp max+37h (00401057) 16. 0040104E mov ecx,dword ptr [ebp-0Ch] 17. 00401051 add ecx,1 18. 00401054 mov dword ptr [ebp-0Ch],ecx 19. 00401057 mov edx,dword ptr [ebp-0Ch] 20. 0040105A cmp edx,dword ptr [ebp+8] 21. 0040105D jge max+61h (00401081) { int t= va_arg (ap, int); 22. 0040105F mov eax,dword ptr [ebp-4] 23. 00401062 add eax,4 24. 00401065 mov dword ptr [ebp-4],eax 25. 00401068 mov ecx,dword ptr [ebp-4] 26. 0040106B mov edx,dword ptr [ecx-4] 27. 0040106E mov dword ptr [t],edx if ( t > m ) 28. 00401071 mov eax,dword ptr [t] 29. 00401074 cmp eax,dword ptr [ebp-8] 30. 00401077 jle max+5Fh (0040107f) m = t; 31. 00401079 mov ecx,dword ptr [t] 32. 0040107C mov dword ptr [ebp-8],ecx } 33. 0040107F jmp max+2Eh (0040104e) va_end (ap); 34. 00401081 mov dword ptr [ebp-4],0 return m; 35. 00401088 mov eax,dword ptr [ebp-8] } 36. 0040108B pop edi 37. 0040108C pop esi 38. 0040108D pop ebx 39. 0040108E mov esp,ebp 40. 00401090 pop ebp 41. 00401091 ret |