assembly - 在 x86 汇编中是否可以用 mul 乘以立即数?

标签 assembly x86 dos multiplication immediate-operand

我正在使用 DosBox 模拟器学习 x86 的汇编。我正在尝试执行乘法。我不明白它是如何工作的。当我编写以下代码时:

mov al, 3
mul 2

我收到一个错误。尽管在我使用的引用文献中,它以乘法表示,但它假设 AX 始终是占位符,因此,如果我写:

mul, 2

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

当我尝试以下操作时:

mov al, 3
mul al,2
int 3

我在 ax 中得到结果 9。请参阅此图片以进行澄清: enter image description here

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

mov si,100
mul [si],5

最佳答案

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

要么:

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

或(立即数需要 186):

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

或者:

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

或者:

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

关于assembly - 在 x86 汇编中是否可以用 mul 乘以立即数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20499141/

相关文章:

c++ - Borland C++ v3 for DOS 现在可以在任何地方使用吗?

multithreading - CAS 碰撞的 CPU 内部特性是什么?

c - 在实现我自己的互斥锁时,如何从内联汇编中引用 C 中的指针

java - 在 Java/DOS-UNIX 中获取文件格式

linux - 创建包含引导加载程序和内核的可引导软盘时出错

performance - 如何解释矩阵乘法 GFLOP/s 中的这种差异?

batch-file - 交互式批处理文件

assembly - 既然有了编译器,为什么还需要汇编器呢?

c - 如何使用堆栈从函数返回值?

assembly - 在MIPS中读取文件时,它读取最后一行两次