This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

关于状态寄存器中状态位的问题

您好!

MSP430X4XX的userguide里面介绍的指令:

BIT[.W] Test bits in destination

BIT.B Test bits in destination

Syntax BIT src,dst or BIT.W src,dst

Operation src .AND. dst

Description The source and destination operands are logically ANDed. The result affects

only the status bits. The source and destination operands are not affected.

Status Bits N: Set if MSB of result is set, reset otherwise

Z: Set if result is zero, reset otherwise

C: Set if result is not zero, reset otherwise (.NOT. zero)

V: Reset

其中关于状态位的描述“reset otherwise”和“reset otherwise (.NOT. zero)”到底是什么意思?

是不确定的意思吗?那以这些位来判断,到底准不准?

  • 你好!

    C Z 都是状态寄存器里面的状态位,状态寄存器是CPU寄存器。

    C:Carry Bit

    Z: Zero Bit

    你提到的“C: Set if result is not zero, reset otherwise (.NOT. zero)”应该这样解读:

    如果这条指令结果不为零,则C = 1;反之如果为零,则为0;(Carry Bit 的结果 = Zero Bit 结果取反)。

  • 您好,感谢您的解答。不过我还是有遗憾,不知道您的解答是基于您对这句英文的翻译,还是基于对芯片了解和实验?

    我觉得这句英文的中文翻译不是您解释的。“reset otherwise (.NOT. zero)”” 应该是“否则,复位(不是0)”;就是说,如果指令结果为0,C位被复位,不一定是0.

    另外,我在实际编程的时候,确实发现指令结果为0,但是C位不为0.

  • 你好!

    这是正确的解释。

    楼主可以做个实验:

    volatile  UINT8_T  a = 0x02;

    volatile  UINT8_T  b = 0x04;

    volatile  UINT8_T  res = 0;

    void  main  (void)

    {

        while(1) {

            res = a & a;

            res = a & b;

        }

    }

    用CCS debug ,汇编单步 assembly step over,在registers 窗口中观察 Core registers 里 SR 中 C Z 位结果。