重学C第四节:第一章结束练习

第四题:进行输出打印

1 #include <stdio.h>
2 
3 void main()
4 {
5     printf("*****************************\n");
6     printf("\tVery good!\t\t\n");
7     printf("*****************************\n");
8 }

第五题:输入a,b,c三个值,输出其中最大者。

 1 #include <stdio.h>
 2 
 3 void main()
 4 {
 5     int max(int x,int y);  //函数的声明
 6     int a,b,c; 
 7     scanf("%d,%d,%d",&a,&b,&c);   //获得输入
 8     printf("%d",max(a,max(b,c)));
 9 }
10 
11 int max(int x,int y)
12 {
13     return ( x>y ? x : y );
14 }

===========================2012-5-11=============================

 1 ; int __cdecl main(int argc, const char **argv, const char **envp)
 2 _main proc near
 3 
 4 var_C= dword ptr -0Ch
 5 var_8= dword ptr -8
 6 var_4= dword ptr -4
 7 argc= dword ptr  4
 8 argv= dword ptr  8
 9 envp= dword ptr  0Ch
10 
11 sub     esp, 0Ch
12 lea     eax, [esp+0Ch+var_C]
13 lea     ecx, [esp+0Ch+var_8]
14 lea     edx, [esp+0Ch+var_4]
15 push    eax
16 push    ecx
17 push    edx
18 push    offset Format   ; "%d,%d,%d"
19 call    _scanf
20 mov     eax, [esp+1Ch+var_C]
21 mov     ecx, [esp+1Ch+var_8]
22 push    eax
23 push    ecx
24 call    sub_401050
25 mov     edx, [esp+24h+var_4]
26 push    eax
27 push    edx
28 call    sub_401050
29 push    eax
30 push    offset aD       ; "%d \n"
31 call    _printf
32 add     esp, 34h
33 retn
34 _main endp

修改为:

 1 ; int __cdecl main(int argc, const char **argv, const char **envp)
 2 _main proc near
 3 
 4 c= dword ptr -0Ch
 5 b= dword ptr -8
 6 a= dword ptr -4
 7 argc= dword ptr  4
 8 argv= dword ptr  8
 9 envp= dword ptr  0Ch
10 
11 sub     esp, 0Ch
12 lea     eax, [esp+0Ch+c]
13 lea     ecx, [esp+0Ch+b]
14 lea     edx, [esp+0Ch+a]
15 push    eax
16 push    ecx
17 push    edx
18 push    offset Format   ; "%d,%d,%d"
19 call    _scanf
20 mov     eax, [esp+1Ch+c]
21 mov     ecx, [esp+1Ch+b]
22 push    eax
23 push    ecx
24 call    func_max
25 mov     edx, [esp+24h+a]
26 push    eax
27 push    edx
28 call    func_max
29 push    eax
30 push    offset aD       ; "%d \n"
31 call    _printf
32 add     esp, 34h
33 retn
34 _main endp

这样一来,我们就很容易的看到,程序首先调用了max函数比较b和c的大小,如何再和a比较。

原文地址:https://www.cnblogs.com/tk091/p/2481394.html