Is it possible to immediately multiply by mul in x86 Assembly?

I am learning build for x86 using DosBox emulator. I am trying to do the multiplication. I do not understand how this works. When I write the following code:

mov al, 3 mul 2 

I get an error message. Although in the link I use, she talks about reproduction, she assumes that AX is always a place holder, so if I write:

 mul, 2 

He multiplies the value of al by 2. But this does not work with me.

When I try the following:

 mov al, 3 mul al,2 int 3 

I get a result of 9 in the top. See this image for more details: enter image description here

Another question: can I multiply memory usage directly? Example:

 mov si,100 mul [si],5 
+6
source share
2 answers

There is no MUL form that takes an immediate operand.

Or do:

 mov al,3 mov bl,2 mul bl ; the product is in ax 

or

 mov ax,3 imul ax,2 ; imul is for signed multiplication, but that doesn't matter here ; the product is in ax 

or

 mov al,3 add al,al ; same thing as multiplying by 2 

or

 mov al,3 shl al,1 ; same thing as multiplying by 2 
+11
source

Intel Guide

Intel 64 and IA-32 Software Developer's Guide - Volume 2 Instruction Set Guide - 325383-056US September 2015 The "MUL - Unsigned Multiply" section of the Instruction column contains only:

 MUL r/m8 MUL r/m8* MUL r/m16 MUL r/m32 MUL r/m64 

r/mXX means case or memory: therefore, immediate ( immXX ), such as mul 2 , are not allowed in any of the forms: the processor simply does not support this operation.

This also answers the second question: can be multiplied by memory:

 x: dd 0x12341234 mov eax, 2 mul dword [x] ; eax == 0x24682468 

And it also shows why things like mul al,2 will not work: there is no form that takes two arguments.

As mentioned by Michael, imul has immediate forms, such as IMUL r32, r/m32, imm32 and many others that mul does not have.

+2
source

All Articles