MUL 指令不支持立即数 [英] MUL instruction doesn't support an immediate value

查看:58
本文介绍了MUL 指令不支持立即数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了一些教程和示例,但我无法理解 MUL 指令的工作原理.我使用 ADDSUB 没有问题.很明显,这条指令将其操作数乘以寄存器中的值.

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.

第一个操作数乘以哪个寄存器(eax、ebp、esp 等)?结果存储在哪个寄存器中,以便我可以将其移动到堆栈中?抱歉,我只是在学习 x86 汇编.

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

我明白了,错误:'mul'的后缀或操作数无效.谁能帮帮我?

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

推荐答案

MUL 不能使用立即数作为参数.您必须将9"加载到寄存器中,例如

MUL can't use an immediate value as an argument. You have to load '9' into a register, say,

 movl    $7, %eax
 movl    $9, %ecx
 mull    %ecx

将 eax 乘以 ecx 并将 64 位乘积存储在 edx:eax 中.

which would multiply eax by ecx and store the 64-bit product in edx:eax.

Intel 网站上有关于 x86 汇编指令的全面参考,请参阅此处

There's a good comprehensive reference of x86 assembly instructions on the Intel web site, see here

http://www.intel.com/Assets/PDF/manual/253666.pdf

http://www.intel.com/Assets/PDF/manual/253667.pdf

但这可能是您现在需要的更多信息.

But that is probably far more information that you need now.

这篇关于MUL 指令不支持立即数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆