imul和idiv如何真正运作8086? [英] How does imul and idiv really work 8086?

查看:146
本文介绍了imul和idiv如何真正运作8086?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚8086微处理器的imul和idiv指令如何工作.

I am trying to figure out how the imul and idiv instructions of the 8086 microprocessor work.

我知道这一点:1. mul和div是无符号数的乘法和除法2. imul和idiv也是乘法和除法,但用于带符号的数字

I know this: 1. mul and div are multiplications and division for unsigned numbers 2. imul and idiv, are also multiplications and divisions but for signed numbers

我搜索了所有网络,以及上面我刚才写的内容,这是我找到的唯一信息,但是编写方式不同.

I searched all the web, and what I just wrote above, that's the only info that I've found, but written in different ways.

我有这个:

mov AX, 0FFCEh
idiv AH

因为是啊,这是一个字节,AL = AX/AH(结果)而AH =余数

Because ah it's a byte, AL=AX/AH (the result) and AH=remainder

在收到指令后,我得到 AX = 0032h ,显然余数为0,结果为32.有人可以解释一下如何得出此结果吗?我需要知道如何解释该指令的工作原理(一点一点).

After the instruction I get AX=0032h, obviously 0 remainder, and the result 32. Can somebody explain how it got to this result ? I need to know how to explain how the instruction works (bit by bit).

imul指令也一样.

Same goes with the imul instruction.

我有:

mov AX, 0FF10h
imul AL

因为AL是一个字节,所以乘法结果将保存到AX中.执行imul指令 AX = 0100h 后,为什么不输入F100h呢?

Because AL is a byte, the result of the multiplication will be saved into AX. After the execution of the imul instruction AX=0100h, why isn't it F100h ?

我不了解CPU实际如何执行mul,div,imul和idiv.如果有人可以为我说明这些差异,那么将不胜感激.

I don't how the CPU actually does mul, div, imul and idiv. If somebody could illustrate for me the differences, would really appreciate it.

谢谢!

推荐答案

idiv的一部分答案

mov AX, FFCE
idiv AH

AX = FFCE

AH = FF

否定的定义是它们的最高排名等于1,因此FFCE为负,

definition of negative is that their highest ranked bit equals 1, so FFCE is negative,

因为 1 111 1111 1100 1110

because 1111 1111 1100 1110

,处理器无法处理负片,我们需要有一个正数,这意味着我们要否定这个数字(或者处理器会自动基于排名最高的位来做到这一点)

and processor cannot work with negatives, we need to have positive, that means we negate this number (or processor does this based on highest ranked bit automaticallly)

NEG FFCE

    1111 1111 1100 1110 => 
=>  0000 0000 0011 0001 +1 =>
=>  0000 0000 0011 0010 =>
=>  0032h

然后下一个-AH寄存器为FF-也是负的我们需要肯定的版本,我们否定

then next - AH register is FF - also negative and we need positive version, we negate

    1111 1111 =>
=>  0000 0000 +1 =>
=>  0000 0001 =>
=>  01h

然后,当所有数字均为正数时,我们将计算除数

then when all numbers are positive, we calculate division

32h div 1h,其余0h => AL,32h结果=> AH

32h div 1h, 0h remainder => AL, 32h result => AH

两者均为负数,表示结果为正数,不再需要转换.

both are negative that means that result is positive and needs no more conversions.

mov AX, FF10
imul AL

AL = 10h

imul/mul在参数为8bit时使用AL

imul/mul uses AL when argument is 8bit (which it is)

所以imul AL与

AL * AL => 10h * 10h => 0100h = AX

答案的不愉快部分

mov AX, FF10
imul AH

AH = FF

AL = 10h

所以现在我们有AL * AH => AX

so now we have AL * AH => AX

AL = 10h

AH = FF,它是负数,我们需要正数,我们求反并得到=> 01h

AH = FF which is negative, we need positive, we negate and get => 01h

正相乘

10h * 01h =>0010h

但是由于其中只有一个是负面的,我们必须否定结果,不要丢失开头的零,否则您的答案将是错误的

but as only one of them was negative, we have to negate result, do not lose starting zeros, or your answer will be incorrect

0010h => FFEF +1 => FFF0 = AX

这篇关于imul和idiv如何真正运作8086?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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