Question

So, I've been going along learning PowerPC for simple reversing projects for Xbox, but I always get tangled up on things like this.

    lwz       r11, 0(r29)   # Loads 0x34 from 0x10710 and stores in r11
    lwz       r10, 4(r29)   # Loads 0x64 from 0x10714 and stores in r10
    addi      r11, r11, 0x7F # r11 = 0x34 + 0x7F = r11 = 0xE3
    clrrwi    r10, r10, 7   # r10 = r10 (0x64) + 0xFFFFFF80
    clrrwi    r31, r11, 7   # r31 = r11 (0xE3) & 0xFFFFFF80

Anyways, what I'm having trouble understanding is the last two lines. How could a register have one value + another? And how could another register have one value & another? And if I were to have addition as the next line, what value would I add to? Sorry, this is a weird transition since my native languages are C++ and C# and I don't feel like giving up on this one as it's so much fun despite the troubles I'm having.

Was it helpful?

Solution

I don’t understand the ‘+’ in the comment "# r10 = r10 (0x64) + 0xFFFFFF80”, and it could be a typo. But I understand the comment on the next line, "# r31 = r11 (0xE3) & 0xFFFFFF80”.

If you look at the PowerPC 2.02 Book 1 documentation for 'Rotate Left Word Immediate then AND with Mask M-form’, it shows what is actually done for clrrwi.

clrrwi Rx,Ry,n

is equivalent to

rlwinm Rx,Ry,0,0,31-n

For clrrwi, rlwinm rotates left the word 0 bits, so there is no rotate done for clrrwi instructions. It generates a mask with 1’s in bits 0-24 and zero elsewhere (bits 25-31), so the mask generated for n=7 is 0xFFFFFF80. The rotated data are ANDed with the generated mask, so this is the reason that the comment for the second clrrwi makes sense. clrrwi is generating a mask to clear the right n bits in a word, and 0xFFFFFF80 is the mask used to do the clear.

By the way, 0x34+0x7F=0xB3.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top