asm source code note 1.6_if else分支的实现
发布日期:2021-06-30 22:06:02 浏览次数:2 分类:技术文章

本文共 3315 字,大约阅读时间需要 11 分钟。

源代码

// test1020.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include 
#include
enum eNumberRange{ eNumberRange_0_100 = 1, eNumberRange_100_200, eNumberRange_200_300, eNumberRange_Unknown};/// 判断一个输入数的范围eNumberRange NumJudge(int iNumber);int _tmain(int argc, _TCHAR* argv[]){ int iDigIn = 0; srand( (unsigned)time( NULL ) ); iDigIn = rand(); _tprintf(L"NumJudge(%d) = %d\r\n", iDigIn, NumJudge(iDigIn)); getwchar(); return 0;}/// 如果iNumber在源代码中给定值, Release版编译后, 会优化掉eNumberRange NumJudge(int iNumber){ if ((iNumber >= 0) && (iNumber < 100)) return eNumberRange_0_100; else if ((iNumber >= 100) && (iNumber < 200)) return eNumberRange_100_200; else if ((iNumber >= 200) && (iNumber < 300)) return eNumberRange_200_300; return eNumberRange_Unknown;}
OD反汇编代码

01091000 >/$  6A 00         push    0                                ;  调用srand01091002  |.  FF15 B0200901 call    dword ptr [<&MSVCR90._time64>]   ;  MSVCR90._time6401091008  |.  50            push    eax                              ; /seed01091009  |.  FF15 AC200901 call    dword ptr [<&MSVCR90.srand>]     ; \srand0109100F  |.  83C4 08       add     esp, 801091012  |.  FF15 A8200901 call    dword ptr [<&MSVCR90.rand>]      ; [rand01091018  |.  85C0          test    eax, eax                         ;  rand的出参在eax0109101A  |.  7C 0C         jl      short 01091028                   ;  < 0 , 不是 >=0 ~ <100, next judge0109101C  |.  83F8 64       cmp     eax, 640109101F  |.  7D 0C         jge     short 0109102D                   ;  >= 100, 不是>=0 ~ <100, next judge01091021  |.  B9 01000000   mov     ecx, 1                           ;  0 < N <= 10001091026  |.  EB 2B         jmp     short 01091053                   ;  判断完成01091028  |>  83F8 64       cmp     eax, 640109102B  |.  7C 0E         jl      short 0109103B                   ;  < 100, 不是 >=100 ~ < 200, next judge0109102D  |>  3D C8000000   cmp     eax, 0C801091032  |.  7D 0E         jge     short 01091042                   ;  >= 200, 不是 >=100 ~ < 200, next judge01091034  |.  B9 02000000   mov     ecx, 2                           ;  100 <= N < 20001091039  |.  EB 18         jmp     short 01091053                   ;  判断完成0109103B  |>  3D C8000000   cmp     eax, 0C801091040  |.  7C 0C         jl      short 0109104E                   ;  < 200, 不是 >=200 ~ < 300, next judge01091042  |>  3D 2C010000   cmp     eax, 12C01091047  |.  B9 03000000   mov     ecx, 3                           ;  当成是N = 200~3000109104C  |.  7C 05         jl      short 01091053                   ;  如果小于 300, 就判断完成,  >=200 ~ < 3000109104E  |>  B9 04000000   mov     ecx, 4                           ;  4 = 未知, 不在有效范围内.01091053  |>  51            push    ecx                              ; |ecx 是判断结果, 判断结束, 压入参数, 调用wprintf01091054  |.  50            push    eax                              ; |
01091055 |. 68 04210901 push 01092104 ; |format = "NumJudge(%d) = %d.."0109105A |. FF15 A4200901 call dword ptr [<&MSVCR90.wprintf>] ; \wprintf01091060 |. 83C4 0C add esp, 0C01091063 |. FF15 A0200901 call dword ptr [<&MSVCR90.getwchar>] ; [getwchar01091069 |. 33C0 xor eax, eax0109106B \. C3 retn

转载地址:https://lostspeed.blog.csdn.net/article/details/4632052 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:asm source code note 1.7_switch case分支的实现
下一篇:asm source code note 1.5_while循环的实现

发表评论

最新留言

网站不错 人气很旺了 加油
[***.192.178.218]2024年04月20日 19时31分09秒