Why in this case the offset relative to "pc" is 0x14, not 0x1C or 0x18?

32 Views Asked by At

I'm referring to the 2nd instruction in this example: https://upload.wikimedia.org/wikipedia/commons/e/e4/ELF_Executable_and_Linkable_Format_diagram_by_Ange_Albertini.png

I.e. add r1, pc, #20, while in the hex code it's 14(<- this is what I'm talking about) 10 8F E2.

Note that the code/text section is located at 0x60. The (2nd) instruction in question is at 0x64. The string that it refers to is at 0x80 (see the "STRINGS" section).

I am not familiar with how pc is moved (e.g. before-vs-after instruction is being carried out; always move by instruction length vs. read multiple instructions at the same time). And I'm guessing that this is where my confusion came from.

In my understanding, pc is either at 0x64 (read one instruction, execute, move pc) or 0x68 (read one instruction, move pc, execute). So, in order to refer to the tetx at 0x80, the added value should be 0x1C and 0x18, respectively.

The actual value added is 0x14 (see the hex code in the same example), which seems to say that pc should be at 0x6C (after the 3rd instruction) when the 2nd instruction is being executed.

This doesn't make sense to me. What did I miss?

0

There are 0 best solutions below