简体   繁体   中英

Reversing PowerPC to C

I am not the best when it comes down to bitwise functions but I want to figure out how this works. Once I figure out how this works I can probably figure out the rest.

ori r11, r11, 11

How could that be translated into C? Am I doing it right?

r11 = (r11 | 11);

I know that isn't proper C syntax, I just want a basic understanding of it.

The ori instruction is or immediate: ori RA RS UI

where:

 RA = the resulting register to store the operation result
 RS = the source register for which to use in the operation
 UI is an unsigned 16-bit integer for the operation

You have interpreted it correctly, and your C looks valid as well.

Be aware though, that PowerPC is a big-endian architecture, so if you're planning on comparing any data across platforms that aren't big-endian (such as Intel x86 for example), you will not get the correct results. The syntax doesn't change, the position of the "lower order bits" will.

ori is "OR immediate", so you are correct. The C is ok too, though preferable would be:

r11 |= 11;

The nice thing is, that many PowerPC instructions read exactly like the corresponding C statement. For instance the add command

add r3,r4,r5

is equivalent to the statement

r3 = r4 + r5;

As I said, that applies to most commands. There are exceptions. It does not apply to stores, for instance. Apart from that, you will need to look up each and every mnemonic from the spec.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM