整数乘法
参考博客:https://blog.csdn.net/weixin_43216249/article/details/109315686
imul
imul具有三种格式:
imul 源操作数
这部分和mul大致相同,源操作数不能是立即数,同时注意符号位
imul 寄存器,源操作数
操作数必须是字或者双字,而不能是字节。
imul 寄存器,源操作数,立即数
其中,寄存器用来存放乘积,
实际测试代码:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a;
a=2;
for(int i=0;i!=10;i++)
{
a=a*30;
printf("%d\n",a);
system("pause");
}
system("pause");
return 0;
}
汇编对应代码:
test_mul.exe+1540 - 55 - push rbp
test_mul.exe+1541 - 48 89 E5 - mov rbp,rsp
test_mul.exe+1544 - 48 83 EC 30 - sub rsp,30
test_mul.exe+1548 - E8 13010000 - call test_mul.exe+1660
test_mul.exe+154D - C7 45 FC 02000000 - mov [rbp-04],00000002
test_mul.exe+1554 - C7 45 F8 00000000 - mov [rbp-08],00000000
test_mul.exe+155B - 83 7D F8 0A - cmp dword ptr [rbp-08],0A
test_mul.exe+155F - 74 2C - je test_mul.exe+158D
test_mul.exe+1561 - 8B 45 FC - mov eax,[rbp-04]
test_mul.exe+1564 - 6B C0 1E - imul eax,eax,1E
test_mul.exe+1567 - 89 45 FC - mov [rbp-04],eax
test_mul.exe+156A - 8B 45 FC - mov eax,[rbp-04]
test_mul.exe+156D - 89 C2 - mov edx,eax
test_mul.exe+156F - 48 8D 0D 8A7A0000 - lea rcx,[test_mul.exe+9000]
test_mul.exe+1576 - E8 65660000 - call test_mul.exe+7BE0
test_mul.exe+157B - 48 8D 0D 827A0000 - lea rcx,[test_mul.exe+9004]
test_mul.exe+1582 - E8 695E0000 - call test_mul.exe+73F0
test_mul.exe+1587 - 83 45 F8 01 - add dword ptr [rbp-08],01
test_mul.exe+158B - EB CE - jmp test_mul.exe+155B
test_mul.exe+158D - 48 8D 0D 707A0000 - lea rcx,[test_mul.exe+9004]
test_mul.exe+1594 - E8 575E0000 - call test_mul.exe+73F0
test_mul.exe+1599 - B8 00000000 - mov eax,00000000
test_mul.exe+159E - 48 83 C4 30 - add rsp,30
test_mul.exe+15A2 - 5D - pop rbp
test_mul.exe+15A3 - C3 - ret