问题在理解MUL和放大器;汇编语言的指令IMUL [英] problem in understanding mul & imul instructions of Assembly language

查看:383
本文介绍了问题在理解MUL和放大器;汇编语言的指令IMUL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是从 PC大会由保罗caurter

学习80386

  MUL源


  

      
  • 如果操作数是字节大小,它是由在AL字节乘以
      注册并在结果存储在
      AX的16位
    即可。

  •   

罚款。


  

      
  • 如果源是16位,它是由字在AX与相乘
      32位结果存储在DX:AX

  •   

Q1:为什么DX:AX?为什么不能它EAX / EDX存储?

IMUL 真是混乱

  IMUL DEST,来源1
IMUL DEST,来源1,源2

我理解该表已经问题。

Q2:在表中的第二项。同样,为什么DX:AX。为什么不EAX或EDX?

现在考虑以下code片断:

  IMUL EAX; EDX:EAX = EAX * EAX
MOV EBX,EAX;保存EBX答案
MOV EAX,square_msg; square_msg DB输入的广场,0
调用print_string;输出字符串EAX
MOV EAX,EBX
调用print_int;打印存储在EAX中的int
调用print_nl;打印新的生产线

Q3:它的previsously说,的符号EDX:EAX意味着联想到EDX和EAX寄存器为一个64位与上注册
在EDX 32位和EAX的低位。
所以答案也存储在EDX,对不对?在上面的code,我们没有考虑任何EDX我们只是指EAX
这是怎么还在工作?

Q4:我有问题表中的所有条目的休息。两个n位数(N = 8/16/32位)的最坏的情况下相乘的结果为2n位。如何找上门存储两个16/32位乘法结果的结果相同大小本身注册?


解决方案

Q1 / Q2:x86指令集保持其16位的历史。当执行16位乘法,答案存储在DX:AX。这只是事情是这样的,因为这是它是如何在16位的土地。

Q3:在code你表现有一个bug,如果你试图计算一个数值大于2 ^ 16大的广场,因为code忽略存储在<$ C结果的高32位$ C> EDX 。

Q4:我想你可能会被误读的表。 8位乘法被存储在一个16位结果; 16位乘法被存储在一个32位结果; 32位乘法被存储在一个64位结果。哪条线,你指的具体?

I'm learning 80386 from PC Assembly by paul caurter

  mul source

  • If the operand is byte sized, it is multiplied by the byte in the AL register and the result is stored in the 16 bits of AX.

fine.

  • If the source is 16-bit, it is multiplied by the word in AX and the 32-bit result is stored in DX:AX.

Q1: Why DX:AX ? Why can't it store in EAX / EDX?

imul is really confusing

imul dest, source1
imul dest, source1, source2

I've problem in understanding the table.

Q2: in the 2nd entry of the table. Again, why DX:AX. Why not EAX or EDX?

Now consider following code snippet:

imul eax ; edx:eax = eax * eax
mov ebx, eax ; save answer in ebx
mov eax, square_msg ; square_msg db "Square of input is ", 0
call print_string ; prints the string eax
mov eax, ebx 
call print_int ;  prints the int stored in eax
call print_nl ; prints new line

Q3: Its previsously said that The notation EDX:EAX means to think of the EDX and EAX registers as one 64 bit register with the upper 32 bits in EDX and the lower bits in EAX. So the answer is also stored in edx, right? in the above code we didn't consider any EDX we are just referring to EAX How is this still working?

Q4: I've problem with rest of all entries in the table. worst case multiplication result of two n bit numbers(n = 8/16/32 bits) is 2n bits. How come its storing the result of two 16/32 bit multiplication result in register of same size itself?

解决方案

Q1/Q2: The x86 instruction set maintains its 16-bit history. When doing a 16-bit multiply, the answer is stored in DX:AX. That's just the way it is, because that's how it was in 16-bit land.

Q3: The code you showed has a bug if you try to compute the square of a number larger than 2^16, because the code ignores the high 32 bits of the result stored in edx.

Q4: I think you may be misreading the table. 8-bit multiplications are stored in a 16-bit result; 16-bit multiplications are stored in a 32-bit result; 32-bit multiplications are stored in a 64-bit result. Which line are you referring to specifically?

这篇关于问题在理解MUL和放大器;汇编语言的指令IMUL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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