assemblyx86dosmultiplicationimmediate-operand

Is it possible to multiply by an immediate with mul in x86 Assembly?


I am learning assembly for x86 using DosBox emulator. I am trying to perform multiplication. I do not get how it works. When I write the following code:

mov al, 3
mul 2

I get an error. Although, in the reference I am using, it says in multiplication, it assumes AX is always the place holder, therefore, if I write:

mul, 2

It multiplies al value by 2. But it does not work with me.

When I try the following:

mov al, 3
mul al,2
int 3

I get result 9 in ax. See this picture for clarification: enter image description here

Another question: Can I multiply using memory location directly? Example:

mov si,100
mul [si],5

Solution

  • There's no form of MUL that accepts an immediate operand.

    Either do:

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

    or (requires 186 for imul-immediate):

    mov ax,3
    imul ax,2  ; imul is for signed multiplication, but low half is the same
               ; the product is in ax.  dx is not modified
    

    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