将除法转换为乘法的MagicNumber

将除法转换为乘法的MagicNumber_第1张图片

来个VC 6的例子:
#include <stdio.h>
int main()
{
 int a;
 int b;

 b = rand();
 a = b/9;

 printf("b = %d, a= %d", b , a);
 getchar();
}



.text:00401000                   ; int __cdecl main(int argc, const char **argv, const char *envp)
.text:00401000                   _main proc near ; CODE XREF: start+AFp
.text:00401000 E8 0E 02 00 00        call _rand
.text:00401005 8B C8                 mov ecx, eax
.text:00401007 B8 39 8E E3 38        mov eax, 38E38E39h
.text:0040100C F7 E9                 imul ecx
.text:0040100E D1 FA                 sar edx, 1
.text:00401010 8B C2                 mov eax, edx
.text:00401012 C1 E8 1F              shr eax, 1Fh
.text:00401015 03 D0                 add edx, eax
.text:00401017 52                    push edx
.text:00401018 51                    push ecx
.text:00401019 68 30 70 40 00        push offset ??_C@_0O@DGOM@b?5?$DN?5?$CFd?0?5a?$DN?5?$CFd?$AA@ ; "b = %d, a= %d"
.text:0040101E E8 BF 01 00 00        call _printf 


你可能感兴趣的:(将除法转换为乘法的MagicNumber)