# Can someone check if this is correct please

1. Given that the instruction

cmp.l d0,d1

subtracts d0 from d1 without changing either and then sets the flags accordingly.

What will be the state of the N and Z flags if

a. d0 < d1 =
b. d0 > d1 =
c. d1 = d1 =

## The Attempt at a Solution

a. is negative and N would be set.
b. the result is positive and neither N or Z is set.
c. the result is zero and Z would be set.

## Answers and Replies

CompuChip
Science Advisor
Homework Helper
You mean: in each of the cases where d0 is smaller, equal or greater to d1, is d1 - d0 positive, negative or zero?

i think is zero

Decision Making: In high level languages we use instructions of the form

If A< B then P else Q

Now what actually happens deep down in the machine is a subtraction of the form (A – B) and we look at the sign of the result.

If B is greater than A then the result is negative and N would be set.
If A is equal to B then the result is zero and Z would be set.
If A is greater than B the result is positive and neither N or Z is set.

Lots of combinations are possible e.g. “less than”, “less than or equal to”, “equal to each other”, “is something equal to, less than, or greater than zero” and so on.

Mark44
Mentor
1. Given that the instruction

cmp.l d0,d1

subtracts d0 from d1 without changing either and then sets the flags accordingly.

What will be the state of the N and Z flags if

a. d0 < d1 =
b. d0 > d1 =
c. d1 = d1 =

## The Attempt at a Solution

a. is negative and N would be set.
b. the result is positive and neither N or Z is set.
c. the result is zero and Z would be set.

I don't believe you're thinking about this the right way. As you described it, the cmp d0, d1 instruction evaluates d1 - d0 and sets the N and Z flag, as appropriate. Obviously you aren't working with an x86-type processor, since it would evaluate d0 - d1.
a. If d0 < d1, then d1 - d0 > 0, so no flags get set.
b. If d0 > d1, then d1 - d0 < 0, so the N flag gets set.
c. I'm pretty sure you mean d0 = d1, since the value in d1 will always equal itself. When d0 = d1, the Z flag gets set.

please can you check this if this is correct

cmpi.w #10,d5

What will the states of the N and Z flags would be if

a. d5 = 12 = No flags gets set.
b. d5 = -10 = Z flag gets set.
c. d5 = 5 = N would be set

Mark44
Mentor
please can you check this if this is correct

cmpi.w #10,d5

What will the states of the N and Z flags would be if

a. d5 = 12 = No flags gets set.
b. d5 = -10 = Z flag gets set.
c. d5 = 5 = N would be set
a. correct
b. The N flag gets set, not the Z flag. The subtraction that is performed is -10 - 10, which is -20.
c. correct