看看三目运算符?:到底是怎么回事
程序代码:
void main(void) { int a = 1; int b = 2; int max; max = (a > b) ? a : b; }
下面是编译得到的汇编代码:
程序代码:
; Listing generated by Microsoft (R) Optimizing Compiler Version 16.00.30319.01 TITLE c:\Users\TonyDeng\documents\visual studio 2010\Projects\test4\test4\test.cpp .686P .XMM include listing.inc .model flat INCLUDELIB MSVCRTD INCLUDELIB OLDNAMES PUBLIC _main EXTRN __RTC_Shutdown:PROC EXTRN __RTC_InitBase:PROC ; COMDAT rtc$TMZ ; File c:\users\tonydeng\documents\visual studio 2010\projects\test4\test4\test.cpp rtc$TMZ SEGMENT __RTC_Shutdown.rtc$TMZ DD FLAT:__RTC_Shutdown rtc$TMZ ENDS ; COMDAT rtc$IMZ rtc$IMZ SEGMENT __RTC_InitBase.rtc$IMZ DD FLAT:__RTC_InitBase ; Function compile flags: /Odtp /RTCsu /ZI rtc$IMZ ENDS ; COMDAT _main _TEXT SEGMENT tv65 = -232 ; size = 4 _max$ = -32 ; size = 4 _b$ = -20 ; size = 4 _a$ = -8 ; size = 4 _main PROC ; COMDAT ; 2 : { 00000 55 push ebp 00001 8b ec mov ebp, esp 00003 81 ec e8 00 00 00 sub esp, 232 ; 000000e8H 00009 53 push ebx 0000a 56 push esi 0000b 57 push edi 0000c 8d bd 18 ff ff ff lea edi, DWORD PTR [ebp-232] 00012 b9 3a 00 00 00 mov ecx, 58 ; 0000003aH 00017 b8 cc cc cc cc mov eax, -858993460 ; ccccccccH 0001c f3 ab rep stosd ; 3 : int a = 1; 0001e c7 45 f8 01 00 00 00 mov DWORD PTR _a$[ebp], 1 ; 4 : int b = 2; 00025 c7 45 ec 02 00 00 00 mov DWORD PTR _b$[ebp], 2 ; 5 : int max; ; 6 : ; 7 : max = (a > b) ? a : b; 0002c 8b 45 f8 mov eax, DWORD PTR _a$[ebp] 0002f 3b 45 ec cmp eax, DWORD PTR _b$[ebp] 00032 7e 0b jle SHORT $LN3@main 00034 8b 4d f8 mov ecx, DWORD PTR _a$[ebp] 00037 89 8d 18 ff ff ff mov DWORD PTR tv65[ebp], ecx 0003d eb 09 jmp SHORT $LN4@main $LN3@main: 0003f 8b 55 ec mov edx, DWORD PTR _b$[ebp] 00042 89 95 18 ff ff ff mov DWORD PTR tv65[ebp], edx $LN4@main: 00048 8b 85 18 ff ff ff mov eax, DWORD PTR tv65[ebp] 0004e 89 45 e0 mov DWORD PTR _max$[ebp], eax ; 8 : } 00051 33 c0 xor eax, eax 00053 5f pop edi 00054 5e pop esi 00055 5b pop ebx 00056 8b e5 mov esp, ebp 00058 5d pop ebp 00059 c3 ret 0 _main ENDP _TEXT ENDS END