4

I'm having trouble understanding the structure of invoke-kind/range opcode,

Syntax

invoke-kind/range {vCCCC .. vNNNN}, meth@BBBB

Arguments

A: argument word count (8 bits)

B: method reference index (16 bits)

C:first argument register (16 bits)

N = A + C - 1

As you can see B and C are mentioned in the bytecode syntax but A is not mentioned, Where is the A argument located and what it means exactly?

Thanks.

Kikapi
  • 369
  • 1
  • 2
  • 11

1 Answers1

2

A contains the number of registers that is being passed to the method.

So if you have invoke-static/range {v0 .. v7}, method, then A will be 8, and C is 0. You can see from the formula at the bottom that N, the last register being passed, is calculated as N = A + C - 1, so N = 0 + 8 - 1 = 7

JesusFreke
  • 19,784
  • 5
  • 65
  • 68
  • I still can't understand the structure, The format of the instruction is `3rc`, that means the size of the instruction is `3*16=48bits`, lets say the instruction is `invoke-static/range {v0 .. v7}, method`, first `8bits` are the opcode, next we have `2*16bits` that contains the registers `v0` and `v7`, then we have method reference index which is `16bit`, then the total instruction size will be `8+16+16+16=56bits`, What am I missing? – Kikapi Feb 09 '16 at 19:58
  • 1
    You can find the code for decoding instructions (used by the verifier) here: https://android.googlesource.com/platform/dalvik/+/kitkat-mr2-release/libdex/InstrUtils.cpp#484 . Instructions are stored in 16-bit chunks, so the other 8 bits of the chunk that holds A are unused in `3rc`. – fadden Feb 09 '16 at 22:25
  • 1
    The instruction formats are defined at https://source.android.com/devices/tech/dalvik/instruction-formats.html. The format for 3rc is `AA|op BBBB CCCC`, so we have 8 bits for the number of registers, 8 bits for the opcode, and then 16 bits for the first register and 16 bits for the method reference, for a total of 48 bits. – JesusFreke Feb 10 '16 at 00:16
  • 1
    "next we have 2*16bits that contains the registers v0 and v7" - this is wrong: there are 16 bits to encode v0, and then 8 bits to encode the fact that there are 8 registers. v7 itself isn't encoded directly, it's implied based on the first register and the total number of registers. – JesusFreke Feb 10 '16 at 00:18