装配中带有进位标志,辅助标志和溢出标志 [英] Carry Flag, Auxiliary Flag and Overflow Flag in Assembly

查看:66
本文介绍了装配中带有进位标志,辅助标志和溢出标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法说出装配中的进位标志,辅助标志和溢出标志之间的区别.我目前正在学校学习,老师没有详细说明.请帮助我理解,考试将需要它.我将非常感激!据我所知,当您尝试使用8位数据时,尝试使用携带标志,例如255 + 9,辅助标志是相同的,但仅适用于最后4位?当二进制数有7位并且符号使用8(最左边)时,将使用溢出".

I Cannot seem to tell the difference between the Carry Flag, Auxiliary Flag and Overflow Flag in Assembly. I'm currently studying it in school and the teacher didn't go into any details. Please help me to understand, I will be needing it for the exam. I will be really grateful!! From what I seem to know by now is that the Carry Flag is used when you try, let's say, 255+9 when you only have 8 bits for data, The Auxiliary Flag is the same, but only for the 4 last bits?? And The Overflow is used when you have 7 bits for the binary number and the 8(left-most ) is used for the sign???

推荐答案

运载标志是在以下情况下设置的标志:

Carry Flag is a flag set when:

a)两个无符号数字相加,结果大于保存它的寄存器的容量".例如:我们要添加两个8位数字并将结果保存在8位寄存器中.在您的示例中:255 + 9 = 264,这比8位寄存器可以存储的更多.因此,值"8"将保存在那里(264& 255 = 8)并设置CF标志.

a) two unsigned numbers were added and the result is larger than "capacity" of register where it is saved. Ex: we wanna add two 8 bit numbers and save result in 8 bit register. In your example: 255 + 9 = 264 which is more that 8 bit register can store. So the value "8" will be saved there (264 & 255 = 8) and CF flag will be set.

b)减去两个无符号数,然后从较小的数中减去较大的数.例如:1-2将给您255个结果,并且CF标志将被设置.

b) two unsigned numbers were subtracted and we subtracted the bigger one from the smaller one. Ex: 1-2 will give you 255 in result and CF flag will be set.

辅助标志用作CF,但与BCD一起使用时.因此,当我们在BCD计算中出现上溢或下溢时,将设置AF. 例如:考虑8位ALU单元,当从第3位到第4位有进位(即,从低位半字节到高位半字节)进位时,设置辅助标志. ( Wiki链接)

Auxiliary Flag is used as CF but when working with BCD. So AF will be set when we have overflow or underflow on in BCD calculations. For example: considering 8 bit ALU unit, Auxiliary flag is set when there is carry from 3rd bit to 4th bit i.e. carry from lower nibble to higher nibble. (Wiki link)

溢出标志用作CF,但是当我们处理带符号的数字时.例如,我们想添加两个8位带符号的数字:127 +2.结果为129,但对于8位带符号的数字来说太大了,因此将设置OF.类似,当结果太小时(如-128-1 = -129),超出8位带符号数字的范围.

Overflow Flag is used as CF but when we work on signed numbers. Ex we wanna add two 8 bit signed numbers: 127 + 2. the result is 129 but it is too much for 8bit signed number, so OF will be set. Similar when the result is too small like -128 - 1 = -129 which is out of scope for 8 bit signed numbers.

您可以阅读有关维基百科上标志的更多信息

You can read more about flags on wikipedia

这篇关于装配中带有进位标志,辅助标志和溢出标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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