有符号数除以非-2的幂(MagicNumber为正)
发布日期:2021-06-30 22:10:20 浏览次数:2 分类:技术文章

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

前言

这里写图片描述

试验

// hw.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include 
#include
void fnIdivNeg3(int x) { printf("==========\r\n"); printf("%d\r\n", x/-3);}void fnIdivNeg7(int x) { printf("==========\r\n"); printf("%d\r\n", x/-7);}void fnIdivNeg14(int x) { printf("==========\r\n"); printf("%d\r\n", x/-14);}void fnIdivNeg15(int x) { printf("==========\r\n"); printf("%d\r\n", x/-15);}int main(int argc, char* argv[]){ // hw1_8 验证 : 有符号数除以非-2的幂(MagicNumber为正) fnIdivNeg3(-3*3); fnIdivNeg7(-7*4); fnIdivNeg14(-14*5); fnIdivNeg15(-15*6); fnIdivNeg3(3*3); fnIdivNeg7(7*4); fnIdivNeg14(14*5); fnIdivNeg15(15*6); /** run result ========== 3 ========== 4 ========== 5 ========== 6 ========== -3 ========== -4 ========== -5 ========== -6 请按任意键继续. . . */ system("pause"); return 0;}
.text:00401000 ; =============== S U B R O U T I N E =======================================.text:00401000.text:00401000.text:00401000 fnIdivNeg3      proc near               ; CODE XREF: _main+2p.text:00401000                                         ; _main+1Ep.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, 55555555h  ; step2.text:00401013                 imul    ecx             ; step3.text:00401015                 sub     edx, ecx        ; step4.text:00401017                 add     esp, 4.text:0040101A                 sar     edx, 1          ; step5.text:0040101C                 mov     eax, edx        ; step6.text:0040101E                 shr     eax, 1Fh        ; step7.text:00401021                 add     edx, eax        ; step8.text:00401023                 push    edx.text:00401024                 push    offset aD       ; "%d\r\n".text:00401029                 call    _printf.text:0040102E                 add     esp, 8.text:00401031                 retn.text:00401031 fnIdivNeg3      endp.text:00401031.text:00401031 ; ---------------------------------------------------------------------------.text:00401032                 align 10h.text:00401040.text:00401040 ; =============== S U B R O U T I N E =======================================.text:00401040.text:00401040.text:00401040 fnIdivNeg7      proc near               ; CODE XREF: _main+9p.text:00401040                                         ; _main+25p.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, 6DB6DB6Dh  ; step2.text:00401053                 imul    ecx             ; step3.text:00401055                 sub     edx, ecx        ; step4.text:00401057                 add     esp, 4.text:0040105A                 sar     edx, 2          ; 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 fnIdivNeg7      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 fnIdivNeg14     proc near               ; CODE XREF: _main+10p.text:00401080                                         ; _main+2Cp.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, 6DB6DB6Dh  ; step2.text:00401093                 imul    ecx             ; step3.text:00401095                 sub     edx, ecx        ; step4.text:00401097                 add     esp, 4.text:0040109A                 sar     edx, 3          ; 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 fnIdivNeg14     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 fnIdivNeg15     proc near               ; CODE XREF: _main+17p.text:004010C0                                         ; _main+33p.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] ; step1.text:004010CE                 mov     eax, 77777777h  ; step2.text:004010D3                 imul    ecx             ; step3.text:004010D5                 sub     edx, ecx        ; step4.text:004010D7                 add     esp, 4.text:004010DA                 sar     edx, 3          ; step5.text:004010DD                 mov     eax, edx        ; step6.text:004010DF                 shr     eax, 1Fh        ; step7.text:004010E2                 add     edx, eax        ; step8.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 fnIdivNeg15     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    -9.text:00401102                 call    fnIdivNeg3.text:00401107                 push    -28.text:00401109                 call    fnIdivNeg7.text:0040110E                 push    -70.text:00401110                 call    fnIdivNeg14.text:00401115                 push    -90.text:00401117                 call    fnIdivNeg15.text:0040111C                 push    9.text:0040111E                 call    fnIdivNeg3.text:00401123                 push    28.text:00401125                 call    fnIdivNeg7.text:0040112A                 push    70.text:0040112C                 call    fnIdivNeg14.text:00401131                 push    90.text:00401133                 call    fnIdivNeg15.text:00401138                 push    offset aPause   ; "pause".text:0040113D                 call    _my_system.text:00401142                 add     esp, 24h.text:00401145                 xor     eax, eax.text:00401147                 retn.text:00401147 _main           endp.text:00401147.text:00401147 ; ---------------------------------------------------------------------------

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

上一篇:查看google快照
下一篇:有符号数除以非-2的幂(MagicNumber为负)

发表评论

最新留言

留言是一种美德,欢迎回访!
[***.207.175.100]2024年04月16日 04时09分46秒