是否可以在x86 Assembly中用mul乘以立即数? [英] Is it possible to multiply by an immediate with mul in x86 Assembly?

查看:205
本文介绍了是否可以在x86 Assembly中用mul乘以立即数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用DosBox模拟器学习x86的程序集.我正在尝试执行乘法.我不知道它是如何工作的.当我编写以下代码时:

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

我得到一个错误.尽管在我正在使用的参考文献中,它用乘法表示,但它假定AX始终是占位符,因此,如果我这样写:

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

它将al值乘以2.但是它对我不起作用.

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

当我尝试以下操作时:

mov al, 3
mul al,2
int 3

我得到斧头的结果9.请参阅此图片以进行澄清:

I get result 9 in ax. See this picture for clarification:

另一个问题:我可以直接使用内存位置进行乘法运算吗?示例:

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

mov si,100
mul [si],5

推荐答案

没有任何形式的MUL接受立即数操作.

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

可以:

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

或:

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

或:

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

或:

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

这篇关于是否可以在x86 Assembly中用mul乘以立即数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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