有符号数除以非2的幂(MagicNumber为负)
2016-09-10 20:16
471 查看
前言
试验
// hw.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <windows.h> #include <stdlib.h> void fnIdiv28(int x) { printf("==========\r\n"); printf("%d\r\n", x/28); } void fnIdiv29(int x) { printf("==========\r\n"); printf("%d\r\n", x/29); } void fnIdiv30(int x) { printf("==========\r\n"); printf("%d\r\n", x/30); } void fnIdiv31(int x) { printf("==========\r\n"); printf("%d\r\n", x/31); } int main(int argc, char* argv[]) { // hw1_6 验证 : 有符号数除以非2的幂(MagicNumber为负) fnIdiv28(-28*2); fnIdiv29(-29*3); fnIdiv30(-30*4); fnIdiv31(-31*5); fnIdiv28(28*2); fnIdiv29(29*3); fnIdiv30(30*4); fnIdiv31(31*5); /** ========== -2 ========== -3 ========== -4 ========== -5 ========== 2 ========== 3 ========== 4 ========== 5 请按任意键继续. . . */ system("pause"); return 0; }
.text:00401000 ; =============== S U B R O U T I N E ======================================= .text:00401000 .text:00401000 .text:00401000 fnIdiv28 proc near ; CODE XREF: _main+2p .text:00401000 ; _main+21p .text:00401000 .text:00401000 arg_0 = dword ptr 4 .text:00401000 .text:00401000 push offset Format ; "==========\r\n" .text:00401005 call _printf .text:0040100A mov ecx, [esp+4+arg_0] ; step1 .text:0040100E mov eax, 92492493h ; step2 .text:00401013 imul ecx ; step3 .text:00401015 add edx, ecx ; step4 .text:00401017 add esp, 4 .text:0040101A sar edx, 4 ; step5 .text:0040101D mov eax, edx ; step6 .text:0040101F shr eax, 1Fh ; step7 .text:00401022 add edx, eax ; step8 .text:00401024 push edx .text:00401025 push offset aD ; "%d\r\n" .text:0040102A call _printf .text:0040102F add esp, 8 .text:00401032 retn .text:00401032 fnIdiv28 endp .text:00401032 .text:00401032 ; --------------------------------------------------------------------------- .text:00401033 align 10h .text:00401040 .text:00401040 ; =============== S U B R O U T I N E ======================================= .text:00401040 .text:00401040 .text:00401040 fnIdiv29 proc near ; CODE XREF: _main+9p .text:00401040 ; _main+28p .text:00401040 .text:00401040 arg_0 = dword ptr 4 .text:00401040 .text:00401040 push offset Format ; "==========\r\n" .text:00401045 call _printf .text:0040104A mov ecx, [esp+4+arg_0] ; step1 .text:0040104E mov eax, 8D3DCB09h ; step2 .text:00401053 imul ecx ; step3 .text:00401055 add edx, ecx ; step4 .text:00401057 add esp, 4 .text:0040105A sar edx, 4 ; step5 .text:0040105D mov eax, edx ; step6 .text:0040105F shr eax, 1Fh ; step7 .text:00401062 add edx, eax ; step8 .text:00401064 push edx .text:00401065 push offset aD ; "%d\r\n" .text:0040106A call _printf .text:0040106F add esp, 8 .text:00401072 retn .text:00401072 fnIdiv29 endp .text:00401072 .text:00401072 ; --------------------------------------------------------------------------- .text:00401073 align 10h .text:00401080 .text:00401080 ; =============== S U B R O U T I N E ======================================= .text:00401080 .text:00401080 .text:00401080 fnIdiv30 proc near ; CODE XREF: _main+10p .text:00401080 ; _main+2Fp .text:00401080 .text:00401080 arg_0 = dword ptr 4 .text:00401080 .text:00401080 push offset Format ; "==========\r\n" .text:00401085 call _printf .text:0040108A mov ecx, [esp+4+arg_0] ; step1 .text:0040108E mov eax, 88888889h ; step2 .text:00401093 imul ecx ; step3 .text:00401095 add edx, ecx ; step4 .text:00401097 add esp, 4 .text:0040109A sar edx, 4 ; step5 .text:0040109D mov eax, edx ; step6 .text:0040109F shr eax, 1Fh ; step7 .text:004010A2 add edx, eax ; step8 .text:004010A4 push edx .text:004010A5 push offset aD ; "%d\r\n" .text:004010AA call _printf .text:004010AF add esp, 8 .text:004010B2 retn .text:004010B2 fnIdiv30 endp .text:004010B2 .text:004010B2 ; --------------------------------------------------------------------------- .text:004010B3 align 10h .text:004010C0 .text:004010C0 ; =============== S U B R O U T I N E ======================================= .text:004010C0 .text:004010C0 .text:004010C0 fnIdiv31 proc near ; CODE XREF: _main+1Ap .text:004010C0 ; _main+39p .text:004010C0 .text:004010C0 arg_0 = dword ptr 4 .text:004010C0 .text:004010C0 push offset Format ; "==========\r\n" .text:004010C5 call _printf .text:004010CA mov ecx, [esp+4+arg_0] .text:004010CE mov eax, 84210843h .text:004010D3 imul ecx .text:004010D5 add edx, ecx .text:004010D7 add esp, 4 .text:004010DA sar edx, 4 .text:004010DD mov eax, edx .text:004010DF shr eax, 1Fh .text:004010E2 add edx, eax .text:004010E4 push edx .text:004010E5 push offset aD ; "%d\r\n" .text:004010EA call _printf .text:004010EF add esp, 8 .text:004010F2 retn .text:004010F2 fnIdiv31 endp .text:004010F2 .text:004010F2 ; --------------------------------------------------------------------------- .text:004010F3 align 10h .text:00401100 .text:00401100 ; =============== S U B R O U T I N E ======================================= .text:00401100 .text:00401100 .text:00401100 ; int __cdecl main(int argc, const char **argv, const char **envp) .text:00401100 _main proc near ; CODE XREF: start+AFp .text:00401100 push -56 .text:00401102 call fnIdiv28 .text:00401107 push -87 .text:00401109 call fnIdiv29 .text:0040110E push -120 .text:00401110 call fnIdiv30 .text:00401115 push -155 .text:0040111A call fnIdiv31 .text:0040111F push 56 .text:00401121 call fnIdiv28 .text:00401126 push 87 .text:00401128 call fnIdiv29 .text:0040112D push 120 .text:0040112F call fnIdiv30 .text:00401134 push 155 .text:00401139 call fnIdiv31 .text:0040113E push offset aPause ; "pause" .text:00401143 call _my_system .text:00401148 add esp, 24h .text:0040114B xor eax, eax .text:0040114D retn .text:0040114D _main endp .text:0040114D .text:0040114D ; ---------------------------------------------------------------------------
相关文章推荐
- HTMl5开发前介绍
- javaScript实现全屏页面滚动效果(优化)
- HDU 5876 补图求最短路
- Linux基础之bash脚本进阶篇-数组
- Maven run as maven install发生错误
- HDU1269-迷宫城堡
- 腾讯空间、新浪微博、腾讯微博登录接口的使用
- LibGdx文档译读(一)Application接口
- Hdu-5875 Function(树上倍增st算法)
- light oj 1134
- Javascript中类的实现机制(四)
- HTTP请求报文和HTTP响应报文
- FTP数据入库Hive
- bzoj 1604: [Usaco2008 Open]Cow Neighborhoods 奶牛的邻居
- 了解和使用keystone(二)安装keystone
- 快速排序中的partition函数的枢纽元选择,代码细节,以及其标准实现
- 我的selenium日记3
- 层次分析法的matlab的实现
- hdu 5874 构造
- vs2015里给c#添加轮廓折叠功能