68000 Assembly Language - CMPI.B

后端 未结 1 1262
天涯浪人
天涯浪人 2021-01-27 09:04
What are the contents of the CCR and D3 after the following instructions sequence executes? Perform the calculation by hand and show your work.

MOVE.B    #7,D3
CMPI.B           


        
1条回答
  •  南方客
    南方客 (楼主)
    2021-01-27 09:56

    D3 will be unchanged by the CMPI, but of course its low byte will be 7 due to the MOVE. (Thanks to @unwind for pointing this out.)

    The instruction set reference will tell you that CMPI works by subtracting the first operand from the second. It also says that the X flag is not affected, and the others are set according to the result as follows:

    • N: 7-11 < 0, so N=1
    • Z: 7-11 != 0, so Z=0
    • V: 7-11=-4, that's in range for signed numbers, V=0
    • C: 7-11=-4, that is out of range of unsigned numbers, C=1.

    These are the human versions for the flags, the cpu actually uses bitwise logic:

    • N: The most significant bit of the result. In 2's complement represenation, negative numbers have the MSB set.
    • Z: Just a bitwise NAND of all the result bits. Z=1 if all bits are zero.
    • V: This one is tricky. V=(-R7)*(-A7)*B7+R7*A7*(-B7), with R7 being the MSB of the result, A7 and B7 the MSB of the two operands. What this means is that you have a signed overflow if subtracting a negative number from a positive gives you negative number, or if subtracting a positive number from a negative gives you positive.
    • C: the final carry of the subtraction, aka. the 9th bit.

    0 讨论(0)
提交回复
热议问题