#include <stdio.h>
void i_c_c()
{
/*80484d0: 55 push %ebp
80484d1: 89 e5 mov %esp,%ebp
80484d3: 83 ec 28 sub $0x28,%esp
80484d6: c7 45 f4 d2 04 00 00 movl $0x4d2,-0xc(%ebp)
80484dd: c7 45 f0 00 00 00 00 movl $0x0,-0x10(%ebp)*/
int a = 0x4d2;
int b = 0;
/*80484e4: 8b 4d f4 mov -0xc(%ebp),%ecx // ecx = a
80484e7: ba d3 4d 62 10 mov $0x10624dd3,%edx // edx = 0x10624dd3 = 274877907
80484ec: 89 c8 mov %ecx,%eax // eax = a
80484ee: f7 ea imul %edx // edx:eax = 0x10624dd3 * 0x4d2 = 339199337238 = 4EF9DB2316
// edx:eax ==> edx = 4E = 78, eax = F9DB2316
80484f0: c1 fa 06 sar $0x6,%edx // edx = 2^38 / 274877907 = 999.9999 = 1000, (debug)---> edx = 0x4E>>0x6 = 0x1
80484f3: 89 c8 mov %ecx,%eax // eax = a
80484f5: c1 f8 1f sar $0x1f,%eax // eax = a>>0x1f = 0
80484f8: 29 c2 sub %eax,%edx // edx = 1-0 = 1
80484fa: 89 d0 mov %edx,%eax // eax = 1; div operation end
80484fc: 69 c0 e8 03 00 00 imul $0x3e8,%eax,%eax // eax = eax*0x3e8 = 1*0x3e8 = 1000
8048502: 29 c1 sub %eax,%ecx // ecx = ecx-eax = 1234-1000 = 234
8048504: 89 c8 mov %ecx,%eax // eax = 234
8048506: 89 45 f0 mov %eax,-0x10(%ebp)*/
b = a % 1000; // 先做除法运算,再用商乘以除数,然后被除数减去商乘以除数的结果,得到不够整除余下的部分,即为余数
/*8048509: 8b 45 f0 mov -0x10(%ebp),%eax
804850c: 89 44 24 04 mov %eax,0x4(%esp)
8048510: c7 04 24 c4 85 04 08 movl $0x80485c4,(%esp)
8048517: e8 74 fe ff ff call 8048390 <printf@plt>*/
printf("%d\n", b);
/*804851c: c9 leave
804851d: c3 ret */
}
int main()
{
/*804851e: 55 push %ebp
804851f: 89 e5 mov %esp,%ebp
8048521: 83 e4 f0 and $0xfffffff0,%esp
8048524: e8 a7 ff ff ff call 80484d0 <i_c_c>*/
i_c_c();
/*8048529: c9 leave
804852a: c3 ret
804852b: 66 90 xchg %ax,%ax
804852d: 66 90 xchg %ax,%ax
804852f: 90 nop*/
return 0;
}
// code
#include <stdio.h>
void i_c_c()
{
int num = 1234;
int bit = 0;
bit = num % 1000;
printf("bit = %d\n", bit);
}
void main()
{
i_c_c();
}