1

I disassemble my own written code in C to PowerPC assembly, and I can't understand why crclr occurrs before the call to the printf function.

C code

int main()
{
     int a, b, c;
     a = 10;
     b = 2;
     c = a * b;
     printf("%d", c);
     return 0;
}

PowerPC assembly code

stwu r1, -0x10(r1)
mflr r0
stw r0, 0x14(r1)
lis r3, unk_38@h
addi r3, r3, unk_38@l
li r4, 0x14
crclr 4*cr1+eq
bl printf
li r3, 0
lwz r0, 0x14(r1)
mtlr r0
addi r1, r1, 0x10
blr

unk_38:
   .byte 0x25 # %
   .byte 0x64 # d

Could anyone please tell me why?

Thanks in advance :)

1

This might be an artifact of compiler optimization. Note the li r4,0x14 instruction - the compiler optimizes your 2*10 calculation and loads the result, 20, into r4 directly. However, doing the calculation would modify some status bits, which the li doesn't, so the compiler tries to do the same modification using crclr, and the optimizer isn't smart enough to realize that this isn't really neccesary when it precedes a function call.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.