1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Can someone check if this is correct please

  1. Dec 24, 2009 #1
    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

    2. Relevant equations
    a. d0 < d1 =
    b. d0 > d1 =
    c. d1 = d1 =

    3. 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.
  2. jcsd
  3. Dec 24, 2009 #2


    User Avatar
    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?
  4. Dec 24, 2009 #3
    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.
  5. Dec 24, 2009 #4


    Staff: Mentor

    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.
  6. Dec 25, 2009 #5
    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
  7. Dec 25, 2009 #6


    Staff: Mentor

    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
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook