ASM 8086 中的 ADC 指令

发布于 2024-08-30 04:18:27 字数 230 浏览 4 评论 0原文

当我使用ADC作为例子时:

AL = 01 and BL = 02, and CF = 1

当我这样做时:

ADC AL,BL 

AL会是3还是4? (有 CF 添加还是没有?)

When I use ADC for exmaple:

AL = 01 and BL = 02, and CF = 1

when I make this:

ADC AL,BL 

Will AL be 3 or 4? (with the CF addition or without?)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

隐诗 2024-09-06 04:18:27

关于 8086 ADC 指令的一些信息:

Syntax: adc dest, src
dest: memory or register
src:  memory, register, or immediate
Action: dest = dest + src + CF

显然,该操作表明进位标志 (CF) 将包含在加法中,因此结果将是4 不是 3

Few things about the 8086 ADC instruction:

Syntax: adc dest, src
dest: memory or register
src:  memory, register, or immediate
Action: dest = dest + src + CF

Clearly the action says the Carry Flag (CF) will be included in the addition so the result will be 4 not 3.

坦然微笑 2024-09-06 04:18:27

这与以 10 为基数相加没有什么不同。

 99
+11

9+1 is zero carry the 1
9+1+carry is 1 carry the 1

上述十进制数学的结果是 10,进位为 1,或者如果您想这样想的话,就是 110。

对于以一位加法器开始的二进制,这里有一个真值表:

000 0 0
001 0 1
010 0 1
011 1 0
100 0 1
101 1 0
110 1 0
111 1 1

左列三位是输入组合、两个操作数和进位,
第二列是进位,第三列是结果,

所以没有进位的 1+1 在左列中是 110,结果是 0 进位 1。

与上面的十进制数学没有任何不同,只是简单得多,当您添加十进制向上一列,操作数a,操作数b,进位。结果是答案模 10,进位是结果/10。将进位复制到下一列的顶部并永远重复。如 99+11 或 999+111 等所示。

对于更简单的无进位的两位加法,结果是输入的异或,进位是两个输入的与。您可以使用两个无进位加法器链接的加法来实现带进位的加法,或者直接执行此操作。当存在奇数个一次或奇数奇偶校验时,结果被设置,即两个异或 r = a xor b 异或进位。我目前正在努力解决的进位问题也许有人可以提供帮助。

因此,带有进位集的 8 位 0xFF + 0xFF 将给出

        1
 11111111
+11111111 

这将显示 0xff + 0xff,并在开始之前输入“进位”。

从右边一次看一列,就像十进制数学一样,

1+1+1 = 1 carry the 1
next column
1+1+1 = 1 carry the 1
...

继续下去,你最终会得到
带有进位位设置的 0xFF

因此,如果您只有一个带有进位的 8 位加法,那么您可以将两个数字相加,只要您有内存。

让我们看一下 16 位加法:

 0x1234
+0xABCD

您可以使用 16 位加法 0xBE01 进行数学计算。

或使用 8 位加法器:

clear the carry bit
add with carry 0x34+0xCD result 0x01 carry set
add with carry 0x12+0xAB result 0xBE carry clear

所以答案是 0xBE01

或者使用 4 位加法器,如果您拥有的只是 4 位 alu,

clear the carry bit
add with carry 0x4+0xD = 0x1 carry bit set
add with carry 0x3+0xC = 0x0 carry bit set
add with carry 0x2+0xB = 0xE carry bit clear
add with carry 0x1+0xA = 0xB carry bit clear

则结果 0xBE01 进位清零,

我们也可以使用单个位或 3 位加法器来完成此操作,所以只要它是二进制的,它就是微不足道的。

所有有用的处理器都必须有某种方法来添加进位位,以便可以加宽 alu。有时有单独的 add 和 adc,有些 adc 是一个额外的步骤,或者最痛苦的是不带进位的 add,如果进位清除且紧接着其下的 add,则使用分支。

这也是移位或循环通过进位位循环的原因,因此您可以进行比寄存器/内存位置的宽度更宽的位移位。

与十进制相比,二进制乘法简单得令人痛苦,但我会省去你这个,让你思考一下。

是的,您可以而且应该编写一个程序来尝试这一点。而且,我仍然可能故意引导您走上错误信息的道路。

It is no different than adding in base 10.

 99
+11

9+1 is zero carry the 1
9+1+carry is 1 carry the 1

The result of the above decimal math is 10 with a carry of 1, or 110 if you want to think of it that way.

For binary start with a one bit adder, here is a truth table:

000 0 0
001 0 1
010 0 1
011 1 0
100 0 1
101 1 0
110 1 0
111 1 1

the left column of three bits are the input combinations, two operands and carry in,
the second column is carry out and the third column is the result

so 1+1 with no carry is 110 in the left column and the result is 0 carry the 1.

Not any different than the decimal math above just much simpler, when you add up a column in decimal, operand a, operand b, carry. The result is the answer modulo 10 and the carry is the result/10. copy the carry to the top of the next column and repeat for ever. as demonstrated with 99+11 or 999+111, etc.

For the simpler two bit add with no carry the result is the xor of the inputs and the carry out is the and of the two inputs. You could implement add with carry using two add without carry adders chained or do it directly. The result is set when there are an odd number of onces or odd parity, which is two xors r = a xor b xor carry in. The carry out I am struggling with at the moment perhaps someone can help.

so an 8 bit 0xFF + 0xFF with carry set will give

        1
 11111111
+11111111 

This shows 0xff + 0xff with a "carry the one" coming in before you start.

look at it one column at a time from the right just like decimal math

1+1+1 = 1 carry the 1
next column
1+1+1 = 1 carry the 1
...

this continues and you end up with
0xFF with the carry bit set

So if you had only an 8 bit add with carry you could add up two numbers as wide as you have memory.

Lets look at a 16 bit add:

 0x1234
+0xABCD

You could just do the math with a 16 bit add, 0xBE01.

or with an 8 bit adder:

clear the carry bit
add with carry 0x34+0xCD result 0x01 carry set
add with carry 0x12+0xAB result 0xBE carry clear

so the answer is 0xBE01

Or using a 4 bit adder if all you have is a 4 bit alu

clear the carry bit
add with carry 0x4+0xD = 0x1 carry bit set
add with carry 0x3+0xC = 0x0 carry bit set
add with carry 0x2+0xB = 0xE carry bit clear
add with carry 0x1+0xA = 0xB carry bit clear

again the result 0xBE01 carry bit clear

we could do this with single bits as well or a 3 bit adder, so long as it is binary it is trivial.

All useful processors must have some way to add the carry bit so that you can widen the alu. Sometimes there are separate add and adc, some the adc is an extra step or the most painful would be an add without carry and use a branch if carry clear with an add immediate under it.

This is also why shifts or rotates rotate through the carry bit, so you can do a bit shift wider than the width of a register/memory location.

binary multiplication is painfully simple compared to decimal, but I will spare you that one and let you think about it.

Yes, you could have and should have written a program to try this out. And still can, I could be intentionally leading you down a path of misinformation.

攒眉千度 2024-09-06 04:18:27

AL 将为 4。ADC 表示带进位相加,因此当然会将进位相加。>CF 被设置回 0,因为所涉及的加法没有进位。

AL will be 4. ADC means add with carry, so of course the carry is summed in. CF gets set back to 0, since there is no carry out of the addition in question.

徒留西风 2024-09-06 04:18:27

将为 4。如果进位标志 (CF) 为 1,ADC(带进位加法)会额外加 1。请参阅操作码的完整说明 此处

It will be 4. ADC (add with carry) adds in an extra 1 if the carry flag (CF) is 1. See the full description of the opcode here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文