asm source code note 1.7_switch case分支的实现
源代码
// test1020.cpp : Defines the entry point for the console application.
//#include "stdafx.h"
#include <windows.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>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)
{eNumberRange eType = eNumberRange_Unknown;int iRange = (iNumber - iNumber % 100) / 100 + eNumberRange_0_100;switch (iRange){case eNumberRange_0_100:eType = eNumberRange_0_100;break;case eNumberRange_100_200:eType = eNumberRange_100_200;break;case eNumberRange_200_300:eType = eNumberRange_200_300;break;default:eType = eNumberRange_Unknown;break;}return eType;
}
OD反汇编代码
002E1000 >/$ 56 push esi
002E1001 |. 6A 00 push 0
002E1003 |. FF15 B0202E00 call dword ptr [<&MSVCR90._time64>] ; MSVCR90._time64
002E1009 |. 50 push eax ; /seed
002E100A |. FF15 AC202E00 call dword ptr [<&MSVCR90.srand>] ; \srand
002E1010 |. 83C4 08 add esp, 8
002E1013 |. FF15 A8202E00 call dword ptr [<&MSVCR90.rand>] ; [rand
002E1019 |. 8BF0 mov esi, eax ; 通过修改eax, 判断常量除法的除数 eax = 0x1234(4660)
002E101B |. B8 1F85EB51 mov eax, 51EB851F ; >> 除法1
002E1020 |. F7EE imul esi
002E1022 |. C1FA 05 sar edx, 5
002E1025 |. 8BC2 mov eax, edx
002E1027 |. C1E8 1F shr eax, 1F
002E102A |. 03C2 add eax, edx
002E102C |. 8BC8 mov ecx, eax ; eax = 0x2e(46), 貌似被除数的百位数, (4660 - 60) % 100
002E102E |. 6BC9 64 imul ecx, ecx, 64 ; 执行后: ecx = 0x11f8(4600), 貌似 (4660 - (4660 % 100))
002E1031 |. B8 1F85EB51 mov eax, 51EB851F ; >> 除法2
002E1036 |. F7E9 imul ecx
002E1038 |. C1FA 05 sar edx, 5
002E103B |. 8BCA mov ecx, edx
002E103D |. C1E9 1F shr ecx, 1F
002E1040 |. 8D440A 01 lea eax, dword ptr [edx+ecx+1] ; ///< eax = 0x2f(47), 貌似入参的百位数 + 1
002E1044 |. 83E8 01 sub eax, 1 ; ///< 看来0~400是有效输入; Switch (cases 1..3)
002E1047 |. 74 1F je short 002E1068 ; ///< 百位数减到第几次为0了, 就match了
002E1049 |. 83E8 01 sub eax, 1
002E104C |. 74 13 je short 002E1061
002E104E |. 83E8 01 sub eax, 1
002E1051 |. 74 07 je short 002E105A
002E1053 |. B8 04000000 mov eax, 4 ; Default case of switch 002E1044
002E1058 |. EB 13 jmp short 002E106D
002E105A |> B8 03000000 mov eax, 3 ; Case 3 of switch 002E1044
002E105F |. EB 0C jmp short 002E106D
002E1061 |> B8 02000000 mov eax, 2 ; Case 2 of switch 002E1044
002E1066 |. EB 05 jmp short 002E106D
002E1068 |> B8 01000000 mov eax, 1 ; Case 1 of switch 002E1044
002E106D |> 50 push eax ; |<%d>
002E106E |. 56 push esi ; |<Nu>
002E106F |. 68 04212E00 push 002E2104 ; |format = "NumJudge(%d) = %d.."
002E1074 |. FF15 A4202E00 call dword ptr [<&MSVCR90.wprintf>] ; \wprintf
002E107A |. 83C4 0C add esp, 0C
002E107D |. FF15 A0202E00 call dword ptr [<&MSVCR90.getwchar>] ; [getwchar
002E1083 |. 33C0 xor eax, eax
002E1085 |. 5E pop esi
002E1086 \. C3 retn
常量除数的除法, 比较难判断被除数是多少。 暂时只能猜~, 如果靠常用除数常量表判断, 也不通用。
通过修改常量除数除法的入参, 从除法结果来判断除法到底除的是常量几, 还算好使。
asm source code note 1.7_switch case分支的实现相关推荐
- Understanding The React Source Code
Understanding The React Source Code - Initial Rendering (Simple Component) I UI updating, in its ess ...
- Downloading Android Source Code
Git 是 Linux Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码的分布式版本控制软件,它不同于Subversion.CVS这样的集中式版本控制系统.在集中式版本控制系统 ...
- Reverse-engineer Source Code into UML Diagrams
今天同事需要反向生成类图,用PowerDesigner 转了一份,不甚满意,在网上逛了逛,发现在这篇文章挺不错. I have been on several teams where we studi ...
- A Transformer-based Approach for Source code Summarization 翻译
A Transformer-based Approach for Source Code Summarization 全文翻译 本文最佳阅读方式:读完一段中文内容快速阅读对应的英文部分 欢迎关注我的公 ...
- Image Dithering: Eleven Algorithms and Source Code Dithering: An Overview
Image Dithering: Eleven Algorithms and Source Code Dithering: An Overview Today's graphics programmi ...
- import openfire4.0.2 source code in eclipse
[0]README 1)本文旨在给出 导入 openfire4.0.2 源码到 eclipse的具体 steps: 2)小生我导入该version 的 openfire 用了近2 天时间, 比较心酸, ...
- Pyinstaller 打包 torch 后执行失败 OSError: could not get source code
1. 问题现象 系统环境 Python 3.6.9 torch 1.2.0 torchvision 0.4.0 Pyinstaller 4.5.1 Pyinstaller 打包 torch 后执行失败 ...
- DevExpress Components16.2.6 Source Code 编译
DevExpress 是一个比较有名的界面控件套件,提供了一系列优秀的界面控件.这篇文章将展示如何在拥有源代码的情况下,对 DevExpress 的程序集进行重新编译. 特别提示:重编译后,已安装好的 ...
- 转: Source Code Lookup in Eclipse(主要讲的是java的)
Source Code Lookup in Eclipse https://www.intertech.com/Blog/source-code-lookup-in-eclipse/
- python3 pycharm 远程调试 启动报错 ValueError: source code string cannot contain null bytes
现象: 启动远程调试时,报错 Traceback (most recent call last):File "/root/.pycharm_helpers/pydev/pydevd.py&q ...
最新文章
- IAR6.1的工程迁移到IAR6.5不能用的解决方法
- sql server 2008学习3 表组织和索引组织
- java事件的接收_spring发布和接收定制的事件(spring事件传播)
- 虚拟机下Ubuntu配置IP地址和网段
- N次剩余(详解+例题+代码)
- 【算法分析与设计】最大连续子序列和问题
- 实例说明代码段(.text)、数据段(.data)、bss段、只读数据段(.rodata)、堆栈的划分依据
- 医保费用监控指标体系建立(九)其他专项分析
- C# winform 跨线程修改界面
- 【linux命令】tar命令
- php 检查货币类型_php 判断函数是否为费用类型(金额/货币:6.02)有小数点
- Java 地心地固坐标系转经纬度(WGS-84大地坐标)
- Java格式化百分比
- VeryCD关闭音乐视频下载视频网站的正版化历程
- 浅析 HTML console
- 刷新存储器的容量单位是什么_存储器存储容量怎么算
- python解压rar文件
- MySQL与PostgreSQL抓取慢sql的方法
- 根据教程编写及完成图书管理系统项目分享
- 华为机试真题 Python 实现【模拟商场优惠打折】【2022.11 Q4 新题】
热门文章
- 计算机应用u盘解释,U盘速度测试和参数解释
- 冲突域和广播域,中继器、集线器、网桥、交换机、路由器和网关
- basemap库安装教程
- 转发:已经足够好用的IDEA社区版
- java能写游戏脚本吗_java能写游戏脚本吗?
- 电子病历基本数据集_电子病历质控的三项是因素-病历质控系统助力提升电子病历质量...
- 串口通信基本接线方法
- 广电linux机顶盒装软件,电视盒子如何安装第三方软件(四种参考方法)
- 【Java】用类描述计算机中CPU的速度和硬盘的容量,要求Java应用程序由4个类,名字分别是PC、CPU、HardDisk、和Test,其中Test是主类。
- k2p B1版本官改关闭路由器ipv6分配