Can someone check if this is correct please

  • Thread starter Thread starter chelsea9947
  • Start date Start date
Click For Summary

Discussion Overview

The discussion revolves around the behavior of the comparison instruction `cmp.l d0, d1` in assembly language, specifically focusing on the resulting states of the N (Negative) and Z (Zero) flags based on different conditions of the operands d0 and d1. The scope includes theoretical understanding and practical implications of flag settings in low-level programming.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • Some participants assert that if d0 < d1, the result of d1 - d0 is positive, hence no flags are set.
  • Others argue that if d0 > d1, the result of d1 - d0 is negative, which would set the N flag.
  • A participant questions the interpretation of the equality case, suggesting that if d0 = d1, the Z flag would be set.
  • In a separate example involving `cmpi.w #10, d5`, one participant states that if d5 = 12, no flags get set, while another participant claims that if d5 = -10, the N flag gets set instead of the Z flag.
  • There is a correction regarding the interpretation of flag settings, indicating that the subtraction performed is -10 - 10, leading to a negative result.

Areas of Agreement / Disagreement

Participants express differing views on the flag settings for the comparison instruction, with no consensus reached on the interpretations of the conditions and outcomes presented.

Contextual Notes

Some assumptions about the processor architecture and the specific behavior of the comparison instruction may not be fully articulated, leading to potential misunderstandings in the discussion.

chelsea9947
Messages
7
Reaction score
0
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

Homework Equations


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.
 
Physics news on Phys.org
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.
 
chelsea9947 said:
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




Homework Equations


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
 
chelsea9947 said:
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
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
2K
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
7K
  • · Replies 146 ·
5
Replies
146
Views
11K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
4
Views
4K
  • · Replies 1 ·
Replies
1
Views
7K
  • · Replies 3 ·
Replies
3
Views
2K