简体   繁体   English

状态寄存器上实际使用了多少位 (8086)

[英]How many bits are actually used on the Status Register (8086)

Asked this in class, I think I understand it but not sure so I wanted to confirm.在课堂上问这个,我想我明白了但不确定所以我想确认一下。

The Status Register has 16 bits, with each bit having a flag.状态寄存器有 16 位,每一位都有一个标志。 However, the image provided in our lecture slides shows otherwise?但是,我们的讲座幻灯片中提供的图片显示的情况并非如此?

状态寄存器

The image shows that only certain bits actually have flags.图像显示只有某些位实际上有标志。 Does this mean that only those bits are actually being used?这是否意味着实际上只使用了那些位? That the rest of the bits are just fodder?其余的部分只是饲料?

I'm sorry if my question is unclear, I can attempt to explain more if anyone asks.如果我的问题不清楚,我很抱歉,如果有人问,我可以尝试解释更多。

Currently , I'm thinking that only 9 bits are actually being used?目前,我在想实际上只使用了 9 位?

In the documentation, it is shown as a «16 bit register» because it is a logical size for a register.在文档中,它显示为“16 位寄存器”,因为它是寄存器的逻辑大小。

In the actual implementation (the way the processor was created) it is often that they will only have the 9 bits.在实际实现中(处理器的创建方式),它们通常只有 9 位。 The other "bits" are lines directly connected to the Ground pin (or +1.2V or whatever the voltage would have been there.) This is because memory is expensive and if you can save a few bits, the hardware is cheaper (think about saving 5 bits x 10 million processors...)其他“位”是直接连接到接地引脚的线(或 +1.2V 或任何可能存在的电压。)这​​是因为内存很昂贵,如果您可以节省一些位,硬件会更便宜(想想节省 5 位 x 1000 万个处理器...)

In newer implementation, I would imagine they do not bother as much, although computers do things like that automatically, so there would again be no reason to have a real bit of memory if it is to keep it to 0 all the time.在较新的实现中,我认为它们不会那么麻烦,尽管计算机会自动执行类似的操作,因此如果要将内存始终保持为 0,则再次没有理由拥有真正的内存。

So as a programmer, as far as you are concerned, it is 16 bits.所以作为程序员,对你来说,就是16位。 For a hardware engineer, it is likely just 9 bits.对于硬件工程师来说,它可能只有9 位。 You just have to make sure that you can still push the flags on the stack properly (that the other 5 bits will always be a known value, in most cases that will be zero).您只需要确保您仍然可以正确地将标志推送到堆栈上(其他 5 位将始终是已知值,在大多数情况下为零)。


Further Details:更多细节:

To access the flag register, as a programmer, you use PUSHF and POPF .要访问标志寄存器,作为程序员,您可以使用PUSHFPOPF

; read to AX
PUSHF
POP AX

; write from AX
PUSH AX
POPF

(As a side note in regard to FUZxxl comments above, the old PUSHF and POPF instructions are 16 bits, the newer versions are 32 or 64 bits. This is important to keep the stack properly aligned.) (作为关于上面 FUZxxl 注释的旁注,旧的 PUSHF 和 POPF 指令是 16 位,新版本是 32 或 64 位。这对于保持堆栈正确对齐很重要。)

As mentioned by Ped7g, although you can put any random value in AX and do a PUSH + POPF , it is not good practice.正如 Ped7g 所提到的,虽然您可以在 AX 中放置任何随机值并执行PUSH + POPF ,但这不是一个好习惯。 Usually, when you want to change a flag for which there is no instruction, you do:通常,当您想更改没有指令的标志时,您可以这样做:

PUSHF
POP AX
OR 10h       ; set flag A to 1
PUSH AX
POPF

The other ways to change a flag is by using certain instructions.更改标志的其他方法是使用某些指令。 This is defined in the instruction directly.这是在指令中直接定义的。 There are a few instructions such as CLD and STC which directly clear or set of flag.有一些指令如CLDSTC直接清除或设置标志。 And there are others such as SBB that will tweak the borrow and ADC that tweak the carry (and N, Z, V flags...)还有其他的,比如SBB会调整借位和ADC调整进位(以及 N、Z、V 标志......)

Finally, there are ways to check the basic flags with branch instructions.最后,有一些方法可以使用分支指令检查基本标志。 In many cases, this is used with the CMP instruction (on newer processor, there are MANY reasons why a flag might change...) This allows you to compare a register against another value and branch if it is smaller, larger, equal, smaller or equal, larger or equal, generates an overflow.在许多情况下,这与CMP指令一起使用(在较新的处理器上,标志可能发生变化的原因有很多......)这允许您将寄存器与另一个值进行比较,如果它更小,更大,相等,小于或等于,大于或等于,会产生溢出。 So an instruction such as JC reads the C flag and jumps if true (set to 1).所以像JC这样的指令读取 C 标志并在为真(设置为 1)时跳转。

In older processors, most of the flags where in link with branches.在较旧的处理器中,大多数标志与分支链接。 The 8086 added the A flag for "Arithmetic" operations (doing additions and subtractions in decimal) and the D flag for "Direction" (see LOOPCX , MOVB ). 8086 添加了用于“算术”运算(以十进制进行加法和减法)的 A 标志和用于“方向”的 D 标志(参见LOOPCXMOVB )。

Later it added many other flags for so many things that I won't list them here.后来它为很多事情添加了许多其他标志,我不会在这里列出它们。 Some of these were useful to know whether a certain instruction existed, and since then we have a CPUID instruction for extensions, everything you need to know about the CPU and it can even be patched at runtime.其中一些对于了解某条指令是否存在很有用,从那时起,我们就有了一个用于扩展的CPUID指令,您需要了解有关 CPU 的所有信息,甚至可以在运行时对其进行修补。

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

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