Search code examples
cpu-architecturedisassemblypowerpcopcode

PowerPC disassembler output different from opcodes


Why are the opcodes for powerpc different from what the disassembler outputs?

Diassambler Output

Disassembly of section .text:

00000000100000b0 <main>:
    100000b0:   38 22 ff f8      addi   r1,r2,-8
    100000b4:   48 00 00 09      bl     100000bc <_main>
    100000b8:   48 00 00 58      b      10000110 <exit>

For instance, for the instruction, "b" the first 6 bits contain the hex value 48. However, on the opcode table, it says that the opcode is 18. Why is this? Am I interpreting the opcodes incorrectly?


Solution

  • 18 is in decimal and is bits 0..5 of the top byte 0..7. So you need to shift it up 2 and convert to hex. Then you get 0x48. ie.

    % printf %x $((18 << 2))
    48 
    %