Check Homework: Compare & Set Flags

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

Discussion Overview

The discussion revolves around a homework problem that requires participants to analyze assembly language instructions related to comparing values and setting flags. The focus is on understanding the implications of these instructions in terms of the flags that are set and the conditions under which branching occurs.

Discussion Character

  • Homework-related
  • Technical explanation
  • Debate/contested

Main Points Raised

  • Some participants explain that the instruction cmpi #$30,d0 sets the Z flag when d0 is $30, leading to the branch instruction beq dan being executed.
  • Others argue that for cmp.l unknown, d0, it cannot be stated that no flags get set without knowing the value of unknown, suggesting the need to consider multiple cases (unknown > d0, unknown < d0, unknown = d0).
  • There is a contention regarding the interpretation of cmp.w d1,d0, with some stating that the N flag gets set, while others emphasize the necessity to analyze different scenarios based on the value of d1.
  • One participant points out that the explanations should be in complete sentences rather than code-like syntax, highlighting the need for clarity in communication.
  • Another participant emphasizes that the bgt dan instruction requires understanding which conditions lead to neither the Z nor N flags being set, indicating a need for a more nuanced explanation.

Areas of Agreement / Disagreement

Participants express differing views on how to articulate the outcomes of the assembly instructions, with some advocating for a more detailed case analysis while others focus on simpler explanations. The discussion remains unresolved regarding the best approach to explain the flag settings and branching conditions.

Contextual Notes

Limitations include the lack of specific values for unknown and d1, which affects the ability to definitively state the outcomes of the comparisons and the resulting flag settings. The discussion also reflects varying interpretations of how to communicate technical concepts effectively.

chelsea9947
Messages
7
Reaction score
0

Homework Statement



If the content of d0 is $30 state in words what each of the following numbered instruction pairs will do.

Homework Equations



a. cmpi #$30,d0

beq dan

b. cmp.l unknown, d0

bne dan

c. cmp.w d1,d0

bgt dan

The Attempt at a Solution



a. cmpi #$30,d0 = Z flag gets set.

beq dan = [go to label dan] [if d0] [equal to zero]


b. cmp.l unknown, d0 = so no flags get set.

bne dan = [go to label dan] [if d0] [not equal to zero]


c. cmp.w d1,d0 = N flag gets set

bgt dan = [go to label dan] [if d0] [greater than zero]
 
Physics news on Phys.org
chelsea9947 said:

Homework Statement



If the content of d0 is $30 state in words what each of the following numbered instruction pairs will do.

Homework Equations



a. cmpi #$30,d0

beq dan

b. cmp.l unknown, d0

bne dan

c. cmp.w d1,d0

bgt dan


The Attempt at a Solution



a. cmpi #$30,d0 = Z flag gets set.

beq dan = [go to label dan] [if d0] [equal to zero]
This is probably closer to how your answers should be "stated in words."
Since d0 is $30, the compare instruction sets the Z flag.
The beq instruction causes a branch to label dan, because the Z flag is set.
chelsea9947 said:
b. cmp.l unknown, d0 = so no flags get set.

bne dan = [go to label dan] [if d0] [not equal to zero]
You can't say that no flags get set, because you don't know what value is stored in unknown. You should look at two cases: unknown == $30 and unknown != $30 (meaning that unknown > $30 or unknown < $30).
The branch instruction will do one thing if the Z flag is set and another if the Z flag is clear. You need to have both cases covered in your explanation.
chelsea9947 said:
c. cmp.w d1,d0 = N flag gets set

bgt dan = [go to label dan] [if d0] [greater than zero]
You can't say that the N flag gets set, because you don't know what value is stored in d1. You should look at two cases: d1 <= d0 and d1 > d0.
You need to have both cases covered in your explanation.
 
cmp.l unknown,d0 = I don’t know what value stored in unknown. Therefore their will be three cases (unknown > d0 or unknown < d0 and unknown = d0)

Unknown > d0 = N flag gets set.
Unknown < d0 = no flags get set
unknown = d0 = Z flag gets set

bne dan = [go to label dan] [if d0] [not equal to zero] cmp.w d1,d0 = I don’t know what value stored in d1. Therefore their will be three cases (d1 < d0 or d1 > d0 and d1 = d0)

d1 > d0 = N flag gets set.
d1 < d0 = no flags get set
d1 = d0 = Z flag gets set

bgt dan = [go to label dan] [if d0] [greater than zero]

is this correct
 
chelsea9947 said:
cmp.l unknown,d0 = I don’t know what value stored in unknown. Therefore their will be three cases (unknown > d0 or unknown < d0 and unknown = d0)

Unknown > d0 = N flag gets set.
Unknown < d0 = no flags get set
unknown = d0 = Z flag gets set

bne dan = [go to label dan] [if d0] [not equal to zero]
This is not correct. You are writing your answers as if you were writing code, which is not what is asked for. You should not be writing your answers like this: bne dan = [go to label dan] [if d0] [not equal to zero]

Write your answers without brackets and in English sentences.

bne dan causes a branch to label dan if the Z flag is clear (not set). Which possibility/possibilities cause this branch to be taken? Note that d0 being zero or not has no influence on things.
chelsea9947 said:
cmp.w d1,d0 = I don’t know what value stored in d1. Therefore their will be three cases (d1 < d0 or d1 > d0 and d1 = d0)

d1 > d0 = N flag gets set.
d1 < d0 = no flags get set
d1 = d0 = Z flag gets set

bgt dan = [go to label dan] [if d0] [greater than zero]

is this correct
No it isn't.
bgt dan causes a branch to label dan if neither the Z flag nor the N flag are set. Which of your three conditions causes neither of these flags to be set?

Your answer should be something like this:
The bgt instruction causes control to flow to label dan if <fill in the blank>. The branch instruction is ignored if <fill in the blank>.
 

Similar threads

Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
1
Views
2K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
7
Views
2K