1

What does the PowerPC instruction cmplw mean and how do i reverse it here is the line.

cmplw     cr6, r31, r10   -----------        r31 = 80 and r10 = 0

Please give me a quick tut on how to reverse this instruction :)

Dko
  • 820
  • 6
  • 12
user3885393
  • 41
  • 2
  • 9
  • A description of all PPC instructions is here: http://cache.freescale.com/files/product/doc/MPC82XINSET.pdf. It's a comparison operator, what does it mean to _reverse_ it? – Barmar Jul 29 '14 at 02:52
  • it means to find out what cr6 = – user3885393 Jul 29 '14 at 02:55
  • but can you make an example of cmplw please so i can understand it better and show the answer – user3885393 Jul 29 '14 at 02:59
  • You mean you want to get back what was in `cr6` before the instruction? I don't think there's any way to do that other than saving the value first. – Barmar Jul 29 '14 at 03:00
  • nvm but can u make an example of that instruction please and can you explain how to do it cause i dont understand it in that pdf file im a noob so i need somthing easier to understand – user3885393 Jul 29 '14 at 03:05

1 Answers1

3

The contents of register r31 and r10 are compared to determine whether they are greater than, less than, equal, or whether there is a summary overflow condition, and the result is placed into the condition register (CR) field 6. The CR field bits are set according to 3.3.9 Fixed-Point Compare Instructions in the PowerPC User ISA Book 1. The CR field in this example is 6 and those fields are numbered such that field 0 is bits 0-3, field 1 is 4-7, and so on. So CR field 6 is bits 24-27 of the condition register, and that is where you'll find the result of greater than, less than, etc.

A CR field is used most commonly by a branch instruction (like bne, beq, blt, etc) to make a flow decision. Without the next related instructions that make a decision based on the CR field, it's hard to write code in C to illustrate what this instruction does. I would say the best estimate of C code for it is something like "r31 == r10", "r31 >= r10", "r31 < r10", and so on, where I can't determine the comparison operator. I also can't determine whether it is "if", "switch", or which conditional operation it would be based on the current information. It all depends on the next related instructions which use the contents of the CR field 6. If the next related instruction were a beq on CR6 then I would expect the C code could be a conditional like "if (r31==r10)". There are many possibilities.

Dko
  • 820
  • 6
  • 12