Alex Rivera | Logout

MUL instruction doesn't support an immediate value

Asked 2010-12-25T04:09:15.707
10

I've read a few tutorials and examples, but I cannot wrap my head around how the MUL instruction works. I've used ADD and SUB without problems. So apparently this instruction multiplies its operand by the value in a register.

What register (eax, ebp, esp, etc.) is multiplied by the first operand? And what register is the result stored in, so I can move it to the stack? Sorry, I'm just learning x86 assembly.

When I try to compile this line...

mul     9

I get, Error: suffix or operands invalid for 'mul'. Can anyone help me out?

    global  main
    main:
    push    ebp
    movl    ebp, esp
    sub     esp, byte +8
    mov     eax, 7
    mul     9
    mov     [esp], eax
    call    _putchar
    xor     eax, eax
    leave
    ret
Edit
Report

1 Answer

3

I'm not an expert but I think your problem is that mul will not accept a direct operand in your case the decimal constant 9 so try putting 9 in let's say register bx like this:

mov bx, 9
mul bx

To answer your question about mul in general it looks like this:

mul     reg/memory

and does that:

dx:ax := ax*reg/mem

So with words it expects a single operand which should either be a register or a memory location (storing the value to be multiplied so essentially a variable) and multiplies it by ax and then depending on how long the register/memory (so the operand you gave) was stores it in either ax or dx:ax or edx:eax

I hope I helped you there pal!

answered 2011-05-19T20:59:01.210

Your Answer