C talk EFAGE register bit, P bit, O bits

  Since writing EFLAGE Bowen, about the C bit, P bit, O bit, I think I have not clearly described, and C bits have not demonstrated it borrow case, P bits are also some pit did not speak, I decided to fix a to fight for a clear description of each flag, see my article is not only to let people can see and understand, but also to consolidate deepen their own knowledge, although no technical stuff, but I have always felt, then it is a trick of cattle build out the foundation, I believe that after one year, two years, or even five or six years of accumulation, but also greatly enriched my knowledge horizons, although not necessarily remember, but a good memory as bad written, when I again do not forget when would, Bowen opened an investigation, certainly there will be a clear insight into feelings, then I would definitely grateful I am now. A thousand miles begins with a single step.

 

Disclaimer: This article is a blogger original article, reproduced, please attach the original source link and this statement. 2019-08-30,00: 40: 11.
By ----- drowning heart of the ups and downs ---- blog Park

 

Carry flag CF (Carry Flag): If the most significant bit of the result produces a carry or borrow, then its value is 1, otherwise its value is 0.

CF: What is the Most Significant bit, what is the highest borrow? -------- not explain the term, trouble, direct look at an example, understand that understand, do not know is to remember the term is useless!

Take example in terms of: We 0x80 - 0x40 example, all derived from the example, do not look at term (8 to 32 as an example ah examples raise to life!)

. 1  1000  0000                    // 0x80 corresponding binary 
2  0100  0000                    // 0x70 corresponding binary 
3 -----------------------

 

See right to left, we press the normal logic value of bit 7 from right to left (according to the angle of the programmer, which is bit 6, bit 1 typically call call bit 0), 0 - 1, not reduced, forward by a former one is which. a number of right-to-left, No. 8, then this is not the highest borrow from bit 1 of it? Our experiments speak!

Since we are doing experiments, in order to facilitate observation, the old rules, all the EFLAGE flag 1

 

 

 Code execution, only to observe the C bit!

 

 

 It is observed that the subtraction result is 0x40, C position is still zero, it is clear from the data in terms of width (the example is eight, for example !!!) We borrowed a 1 from the most significant bit of the 8, but the C bit no changes to 1, our interpretation of what is CF? It is if the highest bit of the result produces a carry or borrow, then its value is 1, otherwise its value is 0.

  Since the C position has not changed, then the first eight is not our highest, the highest level that it is a bit ahead of the first eight (8 your computer has only the default width! We are talking about the example of eight! If you want to tangle 16-bit, 32-bit, 64-bit, test illustrates your own, of course, understand 8, so the back of 16-bit, 32-bit, 64-bit will understand), apparently does not exist in front of the bit, do not exist diminished yet? No, to cut, but we need the number of bits from a non-existent by a number subtracted

  So summing it, resulting in the addition operation result exceeds how to do? Easy to handle, the excess bits are all discarded, do not, I can not keep! Like glass, filled with water, how to do, how to do, its own water overflow ah!

We cite an example, C-bit and set the case due to borrow 1

1 the MOV AL, 80    
2 the SUB AL, 81

 

. 1  1000  0000                         // 0x80 corresponding binary 
2  1000  0001                         // 0x81 corresponding binary 
3 -----------------------------

 

 

 

 We own push, the right number of first cut is not enough, by a 1 to high, middle high is 0, can not borrow, then go straight to borrow, then less complete, the front seven is certainly the result of 11,111,111, the first 8 to borrowed it himself becomes 0, and their reduction is not enough how to do, no way, it does not have to exist to a high of 1 to borrow, (which is what, this is a binary ah! high !! 1 equivalent of a low 2 Yeah, but not 2 ah binary, decimal ten is also not the same) so the subtraction result becomes 1111 1111, we experiment a bit, observe the results.

 

 

 The results in line with our expectations, that we guess is correct! Through the experiment, what I believe is the highest level should be able to understand it!

 

Parity flag PF (Parity Flag): parity flag PF is used to reflect the operation result of the parity of the number of "1".

If the number of "1" is even, the PF 1 value, otherwise its value is 0.

If your hands through the code, changing only the PF EFLAG a flag, I believe that you, like I had met with a situation that is obviously my operation result is an even number of 1 ah why the PF bit is 0 then? According to the official explanation, a parity flag PF for parity calculation result is reflected in the number of "1". If the number of "1" is even, the PF 1 value, otherwise its value is 0. Yes ah, is ah, why obviously operation result is an even number of 1, 0 or why it?

We look at an example

1 MOV AX,0xB03
2 ADD AX,0x1

 

Our own verification again, plus 0x1 0xB03 calculation result is 0xB04, the corresponding binary is 0,000,101,100,000,100, four calculation result is 1, the terms defined above, P bit is a 1, the test time verification.

 

 

 

 

 We found that the results validate the wrong definition of inference, then we add on the basis of the above code on a 1 try, then the result of the operation is 0xB05 is not it! Corresponding binary is 0,000,101,100,000,101, count, a total of five 1, by definition, PF bit is a 0, right, we once experimental verification.

 

 

 又发现我们根据定义推论的结果错误,计算结果偶数个1居然为0,奇数个1居然为1,这不与定义相反吗?这并不相反,PF位实际只是最低字节有效!!!!也就是说,不管你是8位,16位,32位也好(64位我没环境,没测),它只看你最低有效字节(8个位),最低有效字节是偶数个1,那么PF就是1,最低有效字节是奇数个1,那么PF就是0。

与定义相同的测试结果请看博主写的EFALG那篇博文

 

版权声明:本文为博主原创文章,转载请附上原文出处链接和本声明。2019-08-30,00:40:11。
作者By-----溺心与沉浮----博客园

 

溢出标志OF(Overflow Flag):溢出标志OF用于反映有符号数加减运算所得结果是否溢出。

如果运算结果超过当前运算位数所能表示的范围,则称为溢出,OF的值被置为1,否则,OF的值被清为0。

先来说说,计算机是如何判断有溢出的,比如0x80 - 0x40

1 MOV AL,0x80
2 SUB AL,0x40

 

这里需要说明一点,计算机它只会做加法

因此我们可以等同看待下面的代码

1 MOV AL,0x80
2 ADD AL,-40        //OD它会自动将这行代码转换成ADD AL,0xC0

 

因此也等同于下面这段代码,其实也就是这段

MOV AL,0x80
ADD AL,0xC0

 

1000 0000

1100 0000

-------------------

0100 0000

我们前面说过,计算机不管正数与负数,这个取决于使用者怎么定义(char, unsigned char),

(介绍两个概念,本想着全靠实验全部都已白话文形式描述的,结果还是不得不介绍术语了,汗)

符号位

我们这里把它当做有符号位看待,最高位就是符号位

最高有效数值位:紧挨着最高位的旁边那个位,从右往左数,也即第7位

如果符号位有进位,1,没有就是0(什么是符号位有进位?如果最高位相加,往前进位了,之前我们称溢出(针对无符号数),现在我们称有发生进位)

最高有效数值位向符号位产生进位,1,没有就是0。

然后计算机会拿这两个数进行异或(XOR),如果异或结果为1,OF位就为1,如果异或结果为0,OF位就为0

 

如果前面中的EFLAG博文,O位,C位发生进位的那几种情况有弄明白的话,其实这里都是多余的,尽管笔者自己自己也有时候犯懵,也不是说不懂这个,只是这一块的反应会慢一点,但多次举例,反复练习,写笔记,也比刚开始顺溜许多了,或许有一天我还是会懵圈,遗忘,但是我把自己踩过的坑一点不落的写了下来,日后回头看,也会避免将来再去踩坑,希望这些也能够帮助后来者学习。其实文章写到这,我也发现自己写啰嗦了,不过就是有符号,无符号两种情况的溢出与不溢出,但写清楚就是为了能更好的去理解本质,带来的问题就是过于啰嗦,适得其反。但这些的确也是曾经困扰过我的东西,我就是想把这些坑都写一遍,然后在自己脑海中过一遍,熟悉一遍。

最高位进位与溢出的区别:

进位标志表示无符号数运算结果是否超出范围.

溢出标志表示有符号数运算结果是否超出范围.

溢出主要是给有符号运算使用的,在有符号的运算中,有如下的规律:

正 + 正 = 正 如果结果是负数,则说明有溢出

负 + 负 = 负 如果结果是正数,则说明有溢出

正 + 负 永远都不会有溢出.

几种情况-------------------------------------------------

1、无符号、有符号都不溢出

2、无符号溢出、有符号不溢出

3、无符号不溢出、有符号溢出

4、无符号、有符号都溢出

这四种情况在前面EFLAG博文中有介绍举例

------------------------------------------------------------

不知不觉,又要凌晨一点了,就这么点东西,花了2个钟头去整理去复习,也真是够花时间的,呵呵,也没啥,算是对自己成长点点滴滴的记录吧,千里之行,始于足下,这些说对我有用吧,我写这些东西的时间都足够去学很多新知识了,说没用吧,又让我对这些旧知识重新拾了一遍而且有了更深刻的理解。不多说了,睡觉!毕竟还得要上班挣钱把小日子过下去。。。

 

版权声明:本文为博主原创文章,转载请附上原文出处链接和本声明。2019-08-30,00:40:11。
作者By-----溺心与沉浮----博客园

Guess you like

Origin www.cnblogs.com/Reverse-xiaoyu/p/11432831.html
Bit
BIT