Question

When I disassembled my arm elf .so file, I saw the following code:

 170c:  e28fc600    add ip, pc, #0, 12

I only know it is an ARM "add" instruction. But from the ARM reference manual "add" has a syntax like:

op{S}{cond} {Rd}, Rn, Operand2

op{cond} {Rd}, Rn, #imm12               ; Thumb-2 ADD and SUB only

and Operand2 is:

  #constant
  Rm {, shift}

This line of asm should fall down into the syntax:

  op Rd, Rn, #constant

So, the code should means, "add pc and #0 to ip"

Then the question is:

  1. What about the last part of the code ", 12"?
  2. Where did you find these information, GAS manual or ARM manual?

Thanks in advance.

Was it helpful?

Solution

This is probably a part of code which will be changed at link time.

The 12 in the encoding says that the immediate will be right rotated by 12 bits. Obviously that currently does not make sense for a #0. Also the whole opcode is currently nothing more than a fancy

mov ip, pc

Have a look at the code during runtime, probably the #0 changed into something which makes more sense.

The numbers never lie.

           e28fc600

Nibbles

  1. e always
  2. 28 add immediate with no condition codes set.
  3. f Rb is the pc or R15.
  4. c Rd is the ip or R12.
  5. 600 are the shifter ops or zero rotated by 6*2 .

As the instruction is rather bizzare the disassembled output maybe abnormal; normally just the constant is displayed #0xef00 as nobody cares how it is encoded. Also, as this is a shared library, the instruction maybe fixed up via a relocation at run time.

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