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 #11,D3
I know the contents of the D3 register will remain unchanged by i am unsure of how to do the calculation to get the ccr flags.
Could somone please show me the calculation how you did it and what flags are set off and why. I really have a hard time understanding this.
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
, soN=1
Z
:7-11 != 0
, soZ=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 bitwiseNAND
of all the result bits.Z=1
if all bits are zero.V
: This one is tricky.V=(-R7)*(-A7)*B7+R7*A7*(-B7)
, withR7
being the MSB of the result,A7
andB7
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.
来源:https://stackoverflow.com/questions/26423548/68000-assembly-language-cmpi-b