Can someone check if this is correct please

  • Thread starter Thread starter chelsea9947
  • Start date Start date
AI Thread Summary
The discussion focuses on the behavior of the `cmp.l d0, d1` instruction, which subtracts d0 from d1 and sets the N (Negative) and Z (Zero) flags based on the result. If d0 is less than d1, the result is positive, and neither flag is set. If d0 is greater than d1, the result is negative, setting the N flag. When d0 equals d1, the result is zero, and the Z flag is set. The conversation also clarifies the expected flag states for the `cmpi.w #10, d5` instruction under various conditions, correcting misunderstandings about which flags are affected.
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
 
Thread 'Have I solved this structural engineering equation correctly?'
Hi all, I have a structural engineering book from 1979. I am trying to follow it as best as I can. I have come to a formula that calculates the rotations in radians at the rigid joint that requires an iterative procedure. This equation comes in the form of: $$ x_i = \frac {Q_ih_i + Q_{i+1}h_{i+1}}{4K} + \frac {C}{K}x_{i-1} + \frac {C}{K}x_{i+1} $$ Where: ## Q ## is the horizontal storey shear ## h ## is the storey height ## K = (6G_i + C_i + C_{i+1}) ## ## G = \frac {I_g}{h} ## ## C...
Back
Top