AAA如何在8086指令集中工作? [英] how does AAA work in 8086 instruction set?

查看:305
本文介绍了AAA如何在8086指令集中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关该指令如何工作的算法的一些信息:

There is some info regarding the algorithm how the instruction works:

if low nibble of AL > 9 or AF = 1 then:
    AL = AL + 6
    AH = AH + 1
    AF = 1
    CF = 1
else
    AF = 0
    CF = 0
in both cases:
    clear the high nibble of AL. 

Example:
  MOV AX, 15   ; AH = 00, AL = 0Fh
  AAA          ; AH = 01, AL = 05
  RET

但是我面临的问题是当我在上面的示例中将15替换为00FF和00FA之类的数字时,AH中的值增加了02,而不是01!

But the problem i am facing is when I replace 15 in the above example with numbers like 00FF and 00FA the value in AH gets incremented by 02 instead of 01 !!

为什么会有这些变化?

推荐答案

以下是 DAA和AAA 的详细说明:

aaa(加法后为ASCII调整)和daa(加法后为十进制)指令支持BCD算术. BCD值是以二进制形式编码的十进制整数,每个半字节有一个十进制数字(0..9). ASCII(数字)值每个字节包含一个十进制数字,即H.O.字节的半字节应包含零.

The aaa (ASCII adjust after addition) and daa (decimal adjust for addition) instructions support BCD arithmetic. BCD values are decimal integer coded in binary form with one decimal digit (0..9) per nibble. ASCII (numeric) values contain a single decimal digit per byte, the H.O. nibble of the byte should contain zero.

aaa和daa指令修改二进制加法的结果,以将其校正为ASCII或十进制算术.例如,要添加两个BCD值,可以将它们视为二进制数相加,然后再执行daa指令以更正结果.同样,您可以在执行添加指令后使用aaa指令来调整ASCII加法的结果.请注意,这两个指令假定加操作数是正确的十进制或ASCII值.如果将二进制(非十进制或非ASCII)值加在一起,并尝试按照这些说明进行调整,则不会产生正确的结果.

The aaa and daa instructions modify the result of a binary addition to correct it for ASCII or decimal arithmetic. For example, to add two BCD values, you would add them as though they were binary numbers and then execute the daa instruction afterwards to correct the results. Likewise, you can use the aaa instruction to adjust the result of an ASCII addition after executing an add instruction. Please note that these two instructions assume that the add operands were proper decimal or ASCII values. If you add binary (non-decimal or non-ASCII) values together and try to adjust them with these instructions, you will not produce correct results.

不幸的是,名称"ASCII算术"的选择是错误的,因为这些值不是真正的ASCII字符.像"unpacked BCD"这样的名称会更合适.但是,英特尔使用名称ASCII,因此该文本也将这样做以避免混淆.但是,您经常会听到"unpacked BCD"一词来描述这种数据类型.

The choice of the name "ASCII arithmetic" is unfortunate, since these values are not true ASCII characters. A name like "unpacked BCD" would be more appropriate. However, Intel uses the name ASCII, so this text will do so as well to avoid confusion. However, you will often hear the term "unpacked BCD" to describe this data type.

Aaa(通常在add,adc或xadd指令后执行)检查al中的值以防止BCD溢出.它根据以下基本算法工作:

Aaa (which you generally execute after an add, adc, or xadd instruction) checks the value in al for BCD overflow. It works according to the following basic algorithm:

if ( (al and 0Fh) > 9 or (AuxC =1) ) then

    if (8088 or 8086) then 
            al := al + 6
    else 
            ax := ax + 6
    endif

    ah := ah + 1
    AuxC := 1               ;Set auxilliary carry
    Carry := 1              ; and carry flags.

else

    AuxC := 0               ;Clear auxilliary carry
    Carry := 0              ; and carry flags.
endif
al := al and 0Fh

aaa指令主要用于在数字字符串中每个字节正好有一个十进制数字的地方添加数字字符串.该文本不会处理BCD或ASCII数字字符串,因此您现在可以安全地忽略此指令.当然,您可以在需要使用上述算法的任何时间使用aaa指令,但这可能是一种罕见的情况.

The aaa instruction is mainly useful for adding strings of digits where there is exactly one decimal digit per byte in a string of numbers. This text will not deal with BCD or ASCII numeric strings, so you can safely ignore this instruction for now. Of course, you can use the aaa instruction any time you need to use the algorithm above, but that would probably be a rare situation.

daa指令的功能类似于aaa,但它处理打包的BCD(二进制代码十进制)值,而不是aaa处理的每字节一位数字的解压缩值.对于aaa,daa的主要目的是添加BCD数字字符串(每字节两位). daa的算法是

The daa instruction functions like aaa except it handles packed BCD (binary code decimal) values rather than the one digit per byte unpacked values aaa handles. As for aaa, daa's main purpose is to add strings of BCD digits (with two digits per byte). The algorithm for daa is

if ( (AL and 0Fh) > 9 or (AuxC = 1)) then

    al := al + 6
    AuxC := 1               ;Set Auxilliary carry.

endif
if ( (al > 9Fh) or (Carry = 1)) then

    al := al + 60h
    Carry := 1;             ;Set carry flag.

endif

因此,AAA仅在每个字节只有一位小数的情况下才有效,而上面提到的不是这种情况.

So AAA works only in case of one decimal digit per byte which is not the case you mentioned above.

这篇关于AAA如何在8086指令集中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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