If you look at the table of the MUL format, you will notice that it accepts only one register parameter. However, switch to IMUL and you will see that there are many forms that take immediate
6B / r ib IMUL r16, r / m16, imm8 word register โ r / m16 โ sign-extended immediate byte.
6B / r ib IMUL r32, r / m32, imm8 doubleword register โ r / m32 โ sign-extended immediate byte.
REX.W + 6B / r ib IMUL r64, r / m64, imm8 Quadword register โ r / m64 โ sign-extended immediate byte.
69 / r iw IMUL r16, r / m16, imm16 word register โ r / m16 โ immediate word.
69 / r id IMUL r32, r / m32, imm32 doubleword register โ r / m32 โ immediate doubleword.
REX.W + 69 / r id IMUL r64, r / m64, imm32 Quadword register โ r / m64 โ immediate doubleword.
So, to multiply Eax by 9, you can do it
mov eax, 7 imul eax, eax, 9 ; eax = eax*9
Take a closer look and you may also notice that these versions are not expandable. In fact, imul is imul used exclusively for almost all multiplications, because multiplication without extension is the same for signed and unsigned values, and multiplication in high-level languages โโdoes not expand (that is, the output types and input operand types are the same) if you do not bring the operands to more wide type. As a result, modern x86 processors are often optimized for imul and also have much more forms than mul
phuclv
source share