简体   繁体   English

零标志何时设置?

[英]When is the zero flag set?

I'm doing some studying for my exam in computer engineering in mid august. 我正在为8月中旬的计算机工程考试做一些研究。 Some of the exercises are about counting the working register and status register for certain instructions in assembler. 一些练习是关于计算汇编程序中某些指令的工作寄存器和状态寄存器。 I'm struggling to understand how the status register and in particular the zero flag works in this exercise. 我很难理解状态寄存器,特别是零标志在本练习中是如何工作的。 The exercise is about calculating what the value of WREG is after these 11 instructions. 练习是关于计算这11条指令后WREG的价值。 I have written my answers on every line but somehow I don't get the status register and zero flag right: 我已经在每一行都写了我的答案,但不知怎的,我没有得到状态寄存器和零标志:

  1. CLRF WREG; WREG = 0x00 WREG = 0x00
  2. BSF STATUS,C; Carry flag = 1 携带标志= 1
  3. BSF WREG,7; WREG = 0x80 (1000 0000) 7th bit set to 1. WREG = 0x80(1000 0000)第7位设置为1。
  4. RLCF WREG; W = 0x01 and status register 0x03? W = 0x01,状​​态寄存器0x03?
  5. BC MCARRY; We will branch because C is set. 我们将分支,因为C已设置。
  6. ADDLW 0x01; Therefore this line is skipped. 因此跳过此行。
  7. MCARRY DECF WREG; W = 0x00 W = 0x00
  8. MOVLW OxFF; W = 0xFF, status register is somehow 7 here W = 0xFF,状态寄存器在某种程度上是7
  9. BZ MHALT; Z bit is set since line 4. 从第4行开始设置Z位。
  10. INCF WREG; Therefore this line i skipped 因此,这条线我跳过了

11. MHALT GOTO MHALT; 11. MHALT GOTO MHALT;

WREG = 0xFF which is the right answer, but I don't understand what happens with the status register at line 4. Somehow it rotates together with WREG and the value gets put in the status register. WREG = 0xFF这是正确的答案,但我不明白第4行的状态寄存器会发生什么。不知何故,它与WREG一起旋转,值被放入状态寄存器。 And then later the value of the status register is 7 (line 8), which I am so confused about. 然后,状态寄存器的值为7(第8行),我很困惑。 Do any of u have a good explanation that can make me understand what happens with the status register and in particular the zero flag when executing instructions in assembler? 你有没有一个很好的解释可以让我理解状态寄存器会发生什么,尤其是在汇编程序中执行指令时的零标志?

END 结束

It's unclear what you have problem with. 目前还不清楚你有什么问题。 First you mention line 4. As you have correctly commented there, the MSB of WREG is 1, and that gets rotated into C. The original value of C which is also 1 gets rotated into the LSB of WREG. 首先你提到第4行。正如你在那里正确评论的那样,WREG的MSB是1,并且它被旋转到C.C的原始值也是1,旋转到WREG的LSB。 Thus WREG=0x01, C=1 and Z=0. 因此WREG = 0x01,C = 1且Z = 0。 Line 7 will set WREG=0x00, C=1 and Z=1. 第7行将设置WREG = 0x00,C = 1和Z = 1。 The MOVW does not affect flags so line 9 will use the value from line 7 not line 4. MOVW不影响标志,因此第9行将使用第7行的值而不是第4行。

Note that the status register is 0 0 0 N OV Z DC C . 请注意,状态寄存器为0 0 0 N OV Z DC C

WREG = 0x80 C = 1 WREG = 0x80 C = 1

rotate left through carry. 左转通过携带。 The Carry is shifted into the LSBit of WREG and the MSBit of WREG is shifted into the Carry : 进位转入WREG的LSBit,WREG的MSBit转入进位:

WREG = 0x01 C = 1 WREG = 0x01 C = 1

当任何汇编操作(在我的情况下为WREG)导致WREG的内容为0时,设置零标志。

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

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