简体   繁体   English

AF、PF 在现代 asm 中的使用

[英]Uses of the AF, PF in modern asm

I've done some browsing and it seems like the PF and AF are very rarely used, and for a beginner such as myself, can basically be ignored as they rarely if ever will come up.我做了一些浏览,似乎PFAF很少使用,对于像我这样的初学者,基本上可以忽略,因为它们很少出现。 From what I've found it seems the use-cases are:从我发现的情况来看,用例似乎是:

Except for obscure cases, can these two flags be all but ignored?除了晦涩的情况外,这两个标志可以被忽略吗? Or is there ever a time when I should be reading these flags and making use of them?或者有没有时候我应该阅读这些标志并使用它们?

Examples:例子:

# AF (CF on 4th bit)
mov $0b1000, %eax
add $0b1000, %eax # [ AF ]


# PF (num 1's is a multiple of two)
inc %eax # [ PF ]

Except for obscure cases ...除了不为人知的情况...

Depends on what you call "obscure":取决于你所说的“晦涩”:

The AF flag is used for BCD calculations which was supported by the early CPUs (in the case of x86: the 8088) mainly for being used in calculators : AF标志用于 BCD 计算,早期 CPU(在 x86 的情况下:8088)支持的主要用于计算器

Early CPUs did not have floating-point support (in the case of x86 CPUs you could add a separate x87 FPU which was more expensive than the computer itself), and BCD arithmetic was a simple method to perform floating-point calculations if both the input (from the keyboard) and the output (to the display) was given in decimal system.早期的 CPU 没有浮点支持(在 x86 CPU 的情况下,您可以添加一个单独的 x87 FPU,它比计算机本身更昂贵),并且 BCD 算法是一种执行浮点计算的简单方法,如果输入(从键盘)和输出(到显示器)以十进制给出。

I remember some special PASCAL dialect for physics calculations around the year 2000 using BCD arithmetic calculations for high-precision calculations.我记得在 2000 年左右,一些特殊的 PASCAL 方言用于物理计算,使用 BCD 算术计算进行高精度计算。

The PF flag could be used for some cases of hardware access : PF标志可用于某些硬件访问情况

When sending a 7-bit data word with parity over some early RS-232 ports, you actually had to send an 8-bit word (without additional parity);当通过一些早期的 RS-232 端口发送带有奇偶校验的 7 位数据字时,您实际上必须发送一个 8 位字(没有额外的奇偶校验); the 8th bit was the parity that had to be calculated by the CPU.第 8 位是必须由 CPU 计算的奇偶校验。 Using the PF flag calculating this bit is easy!使用PF标志计算这个位很容易!

... in modern asm ... ...在现代汇编...

Or is there ever a time when I should be reading these flags and making use of them?或者有没有时候我应该阅读这些标志并使用它们?

As far as I know, the AF flag was not intended to be read at all even in early x86 CPUs:据我所知,即使在早期的 x86 CPU 中,也不打算读取AF标志:

The flag was only used as input to BCD operations (just like the CF flag is an input to the sbb and adc instructions);该标志仅用作 BCD 操作的输入(就像CF标志是sbbadc指令的输入一样); however, unlike the CF flag it was not intended to "read" AF directly (using a conditional jump operation).然而,与CF标志不同,它不打算直接“读取” AF (使用条件跳转操作)。

So even early x86 programmers did not care about the AF flag but the flag was only used by the CPU in the "background" when BCD arithmetic was done.因此,即使是早期的 x86 程序员也不关心AF标志,但该标志仅在完成 ​​BCD 算法时由 CPU 在“后台”使用。

Using modern operating systems (such as Linux and Windows) only device drivers access the hardware;使用现代操作系统(如 Linux 和 Windows),只有设备驱动程序才能访问硬件; and most modern hardware (for example RS-232 ports) is capable of calculating the parity in hardware.大多数现代硬件(例如 RS-232 端口)都能够计算硬件中的奇偶校验。

So using the PF flag normally is also not necessary.所以通常也没有必要使用PF标志。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM