Difference between revisions of "Assembler:Commands:IMUL"

From Cheat Engine
Jump to navigation Jump to search
m (Reverted edits by This content is not available (Talk) to last revision by TheyCallMeTim13)
 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
[[Category:Assembler]]
 
'''command''' imul ''destination'', ''source1'', ''source2''
 
'''command''' imul ''destination'', ''source1'', ''source2''
  
Line 33: Line 34:
 
The two- and three-operand forms may also be used with unsigned operands because the lower half of the product is the same regardless if the operands are signed or unsigned. The CF and OF flags, however, cannot be used to determine if the upper half of the result is non-zero.
 
The two- and three-operand forms may also be used with unsigned operands because the lower half of the product is the same regardless if the operands are signed or unsigned. The CF and OF flags, however, cannot be used to determine if the upper half of the result is non-zero.
  
[http://x86.renejeschke.de/html/file_module_x86_id_138.html x86.renejeschke.de/html/file_module_x86_id_138.html]
+
[http://c9x.me/x86/html/file_module_x86_id_138.html c9x.me/x86/html/file_module_x86_id_138.html]
 
</div>
 
</div>
  
Line 58: Line 59:
 
  imul ecx,2 // ecx = ecx * 2
 
  imul ecx,2 // ecx = ecx * 2
  
  imul ecx,edx,2 // ecx = ecx * 2
+
  imul ecx,edx,2 // ecx = edx * 2
  
 
  mov eax,3
 
  mov eax,3
Line 75: Line 76:
 
  // eax = 6
 
  // eax = 6
  
== See also ==
+
{{AssemblerCommandSeeAlso}}
* [[Assembler]]
 
* [[Cheat_Engine:Auto Assembler|Auto Assembler]]
 
* [[Assembler:Commands|Assembler Commands]]
 
  
== External links ==
+
{{Template:AssemblerCommandExternalLinks}}
* [https://wikipedia.org/wiki/X86_instruction_listings wikipedia.org/wiki/X86_instruction_listings]
 
* [https://wikibooks.org/wiki/X86_Assembly/Other_Instructions wikibooks.org/wiki/X86_Assembly/Other_Instructions]
 
* [http://x86.renejeschke.de/ x86.renejeschke.de]
 
* [http://www.asmpedia.org/index.php?title=Main_Page asmpedia.org]
 

Latest revision as of 19:09, 18 March 2019

command imul destination, source1, source2

Performs a signed multiplication of two or three operands. This instruction has three forms, depending on the number of operands.

One-operand
This form is identical to that used by the MUL instruction, just signed. Here, the source operand (in a general-purpose register or memory location) is multiplied by the value in the accumulator register and the upper product is stored in the data register and lower product is stored in the accumulator register.
The CF and OF flags are set when significant bits are carried into the upper half of the result and cleared when the result fits exactly in the lower half of the result.
Two-operand
With this form the destination operand (the first operand) is multiplied by the source operand (second operand). The destination operand is a general purpose register and the source operand is an immediate value, a general-purpose register, or a memory location. The product is then stored in the destination operand location.
The CF and OF flags are set when the result must be truncated to fit in the destination operand size and cleared when the result fits exactly in the destination operand size. The SF, ZF, AF, and PF flags are undefined.
Three-operand
This form requires a destination operand (the first operand) and two source operands (the second and the third operands). Here, the first source operand (which can be a general-purpose register or a memory location) is multiplied by the second source operand (an immediate value). The product is then stored in the destination operand (a general-purpose register).
The CF and OF flags are set when the result must be truncated to fit in the destination operand size and cleared when the result fits exactly in the destination operand size. The SF, ZF, AF, and PF flags are undefined.


Performs a signed multiplication of two operands. This instruction has three forms, depending on the number of operands.

One-operand form. This form is identical to that used by the MUL instruction. Here, the source operand (in a general-purpose register or memory location) is multiplied by the value in the AL, AX, or EAX register (depending on the operand size) and the product is stored in the AX, (E)DX:(E)AX.

Two-operand form. With this form the destination operand (the first operand) is multiplied by the source operand (second operand). The destination operand is a general purpose register and the source operand is an immediate value, a general-purpose register, or a memory location. The product is then stored in the destination operand location.

Three-operand form. This form requires a destination operand (the first operand) and two source operands (the second and the third operands). Here, the first source operand (which can be a general-purpose register or a memory location) is multiplied by the second source operand (an immediate value). The product is then stored in the destination operand (a general-purpose register).

When an immediate value is used as an operand, it is sign-extended to the length of the destination operand format.

The CF and OF flags are set when significant bit (including the sign bit) are carried into the upper half of the result. The CF and OF flags are cleared when the result (including the sign bit) fits exactly in the lower half of the result.

The three forms of the IMUL instruction are similar in that the length of the product is calculated to twice the length of the operands. With the one-operand form, the product is stored exactly in the destination. With the two- and three- operand forms, however, the result is truncated to the length of the destination before it is stored in the destination register. Because of this truncation, the CF or OF flag should be tested to ensure that no significant bits are lost.

The two- and three-operand forms may also be used with unsigned operands because the lower half of the product is the same regardless if the operands are signed or unsigned. The CF and OF flags, however, cannot be used to determine if the upper half of the result is non-zero.

c9x.me/x86/html/file_module_x86_id_138.html


Command Parameters[edit]

Parameter Description
destination The destination multiplier operand
source1 Optional The first source multiplier operand
source2 Optional The second source multiplier operand


Examples[edit]

imul ecx // eax = eax * ecx
imul ecx,2 // ecx = ecx * 2
imul ecx,edx,2 // ecx = edx * 2
mov eax,3
mov ecx,2
imul ecx // ecx = eax * ecx
// edx = 0, eax = 6, edx:eax = 6
mov eax,3
mov ecx,2
imul eax,ecx // eax = eax * ecx
// eax = 6
mov eax,10
mov ecx,3
imul eax,ecx,2 // eax = ecx * 2
// eax = 6

See also[edit]

External links[edit]