reshown by
2,188 views
3 votes
3 votes
The instruction format is CMP R1, R2.

How will the carry and zero flags we be modified after above instruction is executed?

 

Case 1:

R1< R2 Carry Flag = 1 Zero Flag = 0

R1= R2 Carry Flag = 0 Zero Flag = 1

R1> R2 Carry Flag = 0 Zero Flag = 0

 

Case 2:

R1< R2 Carry Flag = 0 Zero Flag = 0

R1= R2 Carry Flag = 0 Zero Flag = 1

R1> R2 Carry Flag = 1 Zero Flag = 0

Which one of the above two cases is correct?
reshown by

1 Answer

Best answer
3 votes
3 votes

Case-1 is correct.

You may want to understand the synthetic instruction behind CMP %r1,%r2 which is nothing but subtraction along with modification of condition codes.

http://web.science.mq.edu.au/~mike/comp226/sparc-manual/Synthetic/cmp.html

Therefore, when the two values in the register are equal, the zero CC will be set, but on the other hand, if you remember arithmetic with numbers then if R1< R2 then subtraction will produce borrow resulting in the carry bit is set.

 


Usually, branch instruction with condition codes is used subsequent to CMP instruction while designing a code in assembly.

selected by

Related questions

1 votes
1 votes
1 answer
2
1 votes
1 votes
1 answer
4
amitqy asked Nov 15, 2018
1,515 views
What should I assume as the size of HALT instruction ? HALT instruction comes under which type of instruction