游戏男孩:什么构成“半携带”? [英] Game Boy: What constitutes a "half-carry"?
问题描述
Game Boy Z80 CPU具有半进位标志,我似乎找不到太多有关何时设置/清除它的信息。
The Game Boy Z80 CPU has a half-carry flag, and I can't seem to find much information about when to set/clear it.
我该做什么到目前为止,我们了解的是任何8位加,减,移位或旋转运算(可能还有其他运算)将其设置为result(?)的第4位,而DAA指令以某种方式设置/使用。我不确定16位指令如何影响它,以及是否受到某些寄存器的使用。
What I understand so far is that any 8-bit add, subtract, shift, or rotate operation (and maybe others?) set it to bit 4 of the result(?), and the DAA instruction sets/uses this somehow. What I'm not sure is how 16-bit instructions affect it and whether it's affected or not by the use of certain registers.
推荐答案
这是从第3位到第4位的进位,就像正常的进位标志记录从第7位进位一样。以获得加法运算符的一半进位位:
It's the carry from bit 3 to bit 4, just like the normal carry flag records carry from bit 7. So, e.g. to get the half carry bit in an add:
((a&0xf) + (value&0xf))&0x10
如果应设置一半进位,则给出0x10,否则给出0。从其他相关操作中获得一半收益自然而然-问题是从低半字节到高字节是否有收益。
Which gives 0x10 if half carry should be set, 0 otherwise. Getting half carry from the other relevant ops follows naturally - the questions is whether there was carry from the low nibble to the high.
从角度看,z80具有一个4位ALU并通过执行两个4位运算来执行8位运算。
To put things in perspective, the z80 has a 4bit ALU and performs 8bit ops by doing two 4bit ops. So it gets half carry very naturally, as an intermediate result.
DAA对标志感兴趣,因为如果设置了一半进位,则两位数加起来超过16在低字节中添加;将正确产生进位的进位,但将使低进位的6保持应有的位置低,因为在应产生进位的10和产生时的16之间有六个值。
DAA is interested in the flag because if half carry is set then two digits that add up to more than 16 were added in the low nibble; that will have correctly produced carry into the upper nibble but will have left the low nibble 6 lower than it should be, since there were six more values between 10, when it should have generated carry, and 16, when it did.
这篇关于游戏男孩:什么构成“半携带”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!