欢迎光临!
若无相欠,怎会相见

反汇编学习-C语言实例解析精粹-实例5字符的输出

序言

环境:Windows XP    VS6.0

C代码

/*
输入字符,输出通过转义字符控制的字符
*/

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main()
{
    char c1, c2, c3;
    printf("Please input three chars: ");
    scanf("%c %c %c", &c1, &c2, &c3);
    printf("%s\n%c\n\t%c %c\n %c%c\t\b%c\n", "The output is: ", c1, c2, c3, c1, c2, c3);
    getchar();
    getchar();
    return 0;

}

汇编代码

--- C:\Documents and Settings\Administrator\桌面\Projects\C\No.5.c  -----------------------------------------------------------------------------------
1:    /*
2:    输入字符,输出通过转义字符控制的字符
3:    */
4:
5:    #define _CRT_SECURE_NO_WARNINGS
6:    #include <stdio.h>
7:
8:    int main()
9:    {
00401010   push        ebp
00401011   mov         ebp,esp
00401013   sub         esp,54h
00401016   push        ebx
00401017   push        esi
00401018   push        edi
00401019   lea         edi,[ebp-54h]   
0040101C   mov         ecx,15h
00401021   mov         eax,0CCCCCCCCh
00401026   rep stos    dword ptr [edi]   // 将缓冲区中填充0CCCCCCCCh
10:       char c1, c2, c3;
11:       printf("Please input three chars: ");
00401028   push        offset string "Please input three chars: " (00422058)
0040102D   call        printf (00401500)
00401032   add         esp,4  // 外平栈,函数外平衡堆栈
12:       scanf("%c %c %c", &c1, &c2, &c3);
00401035   lea         eax,[ebp-0Ch]
00401038   push        eax
00401039   lea         ecx,[ebp-8]
0040103C   push        ecx
0040103D   lea         edx,[ebp-4]
00401040   push        edx
00401041   push        offset string "%c %c %c" (0042204c)
00401046   call        scanf (004014a0)
0040104B   add         esp,10h
13:       printf("%s\n%c\n\t%c %c\n %c%c\t\b%c\n", "The output is: ", c1, c2, c3, c1, c2, c3);
0040104E   movsx       eax,byte ptr [ebp-0Ch]
00401052   push        eax
00401053   movsx       ecx,byte ptr [ebp-8]
00401057   push        ecx
00401058   movsx       edx,byte ptr [ebp-4]
0040105C   push        edx
0040105D   movsx       eax,byte ptr [ebp-0Ch]
00401061   push        eax
00401062   movsx       ecx,byte ptr [ebp-8]
00401066   push        ecx
00401067   movsx       edx,byte ptr [ebp-4]
0040106B   push        edx
0040106C   push        offset string "The output is: " (00422038)
00401071   push        offset string "%s\n%c\n\t%c %c\n %c%c\t\x08%c\n" (0042201c)
00401076   call        printf (00401500)
0040107B   add         esp,20h
14:       getchar();
0040107E   mov         eax,[__iob+4 (00424a34)]
00401083   sub         eax,1
00401086   mov         [__iob+4 (00424a34)],eax
0040108B   cmp         dword ptr [__iob+4 (00424a34)],0
00401092   jl          main+0A5h (004010b5)
00401094   mov         ecx,dword ptr [__iob (00424a30)]
0040109A   movsx       edx,byte ptr [ecx]
0040109D   and         edx,0FFh
004010A3   mov         dword ptr [ebp-10h],edx
004010A6   mov         eax,[__iob (00424a30)]
004010AB   add         eax,1
004010AE   mov         [__iob (00424a30)],eax
004010B3   jmp         main+0B5h (004010c5)
004010B5   push        offset __iob (00424a30)
004010BA   call        _filbuf (00401170)
004010BF   add         esp,4
004010C2   mov         dword ptr [ebp-10h],eax
15:       getchar();
004010C5   mov         ecx,dword ptr [__iob+4 (00424a34)]
004010CB   sub         ecx,1
004010CE   mov         dword ptr [__iob+4 (00424a34)],ecx
004010D4   cmp         dword ptr [__iob+4 (00424a34)],0
004010DB   jl          main+0EFh (004010ff)
004010DD   mov         edx,dword ptr [__iob (00424a30)]
004010E3   movsx       eax,byte ptr [edx]
004010E6   and         eax,0FFh
004010EB   mov         dword ptr [ebp-14h],eax
004010EE   mov         ecx,dword ptr [__iob (00424a30)]
004010F4   add         ecx,1
004010F7   mov         dword ptr [__iob (00424a30)],ecx
004010FD   jmp         main+0FFh (0040110f)
004010FF   push        offset __iob (00424a30)
00401104   call        _filbuf (00401170)
00401109   add         esp,4
0040110C   mov         dword ptr [ebp-14h],eax
16:       return 0;
0040110F   xor         eax,eax
17:
18:   }
00401111   pop         edi
00401112   pop         esi
00401113   pop         ebx
00401114   add         esp,54h
00401117   cmp         ebp,esp
00401119   call        __chkesp (00401580)
0040111E   mov         esp,ebp
00401120   pop         ebp
00401121   ret

 

结语

有点儿晚了,有时间在补充~

如有错误,敬请指出,感谢指正!              — 2019-09-04  00:19:45        于苏州

赞(0) 打赏
转载请注明:飘零博客 » 反汇编学习-C语言实例解析精粹-实例5字符的输出
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

欢迎光临