Dalvik Instruction Formats

Dalvik VM Instruction Formats

Copyright © 2007 The Android Open Source Project

Introduction and Overview

This document lists the instruction formats used by Dalvik bytecode and is meant to be used in conjunction with the bytecode reference document.

Bitwise descriptions

The first column in the format table lists the bitwise layout of the format. It consists of one or more space-separated "words" each of which describes a 16-bit code unit. Each character in a word represents four bits, read from high bits to low, with vertical bars ("|") interspersed to aid in reading. Uppercase letters in sequence from "A" are used to indicate fields within the format (which then get defined further by the syntax column). The term "op" is used to indicate the position of the eight-bit opcode within the format. A slashed zero ("Ø") is used to indicate that all bits should be zero in the indicated position.
For example, the format "B|A|op CCCC" indicates that the format consists of two 16-bit code units. The first word consists of the opcode in the low eight bits and a pair of four-bit values in the high eight bits; and the second word consists of a single 16-bit value.

Format IDs

The second column in the format table indicates the short identifier for the format, which is used in other documents and in code to identify the format.
Format IDs consist of three characters, two digits followed by a letter. The first digit indicates the number of 16-bit code units in the format. The second digit indicates the maximum number of registers that the format contains (maximum, since some formats can accomodate a variable number of registers), with the special designation "r" indicating that a range of registers is encoded. The final letter semi-mnemonically indicates the type of any extra data encoded by the format. For example, format "21t" is of length two, contains one register reference, and additionally contains a branch target.
Suggested static linking formats have an additional "s" suffix, making them four characters total.
The full list of typecode letters are as follows. Note that some forms have different sizes, depending on the format:
MnemonicBit SizesMeaning
b8immediate signed byte
c16, 32constant pool index
f16interface constants (only used in statically linked formats)
h16immediate signed hat (high-order bits of a 32- or 64-bit value; low-order bits are all 0)
i32immediate signed int, or 32-bit float
l64immediate signed long, or 64-bit double
m16method constants (only used in statically linked formats)
n4immediate signed nibble
s16immediate signed short
t8, 16, 32branch target
x0no additional data

Syntax

The third column of the format table indicates the human-oriented syntax for instructions which use the indicated format. Each instruction starts with the named opcode and is optionally followed by one or more arguments, themselves separated with commas.
Wherever an argument refers to a field from the first column, the letter for that field is indicated in the syntax, repeated once for each four bits of the field. For example, an eight-bit field labeled "BB" in the first column would also be labeled "BB" in the syntax column.
Arguments which name a register have the form "vX". The prefix "v" was chosen instead of the more common "r" exactly to avoid conflicting with (non-virtual) architectures on which a Dalvik virtual machine might be implemented which themselves use the prefix "r" for their registers. (That is, this decision makes it possible to talk about both virtual and real registers together without the need for circumlocution.)
Arguments which indicate a literal value have the form "#+X". Some formats indicate literals that only have non-zero bits in their high-order bits; for these, the zeroes are represented explicitly in the syntax, even though they do not appear in the bitwise representation.
Arguments which indicate a relative instruction address offset have the form "+X".
Arguments which indicate a literal constant pool index have the form "kind@X", where "kind" indicates which constant pool is being referred to. Each opcode that uses such a format explicitly allows only one kind of constant; see the opcode reference to figure out the correspondence. The four kinds of constant pool are "string" (string pool index), "type" (type pool index), "field" (field pool index), and "meth" (method pool index).
Similar to the representation of constant pool indices, there are also suggested (optional) forms that indicate prelinked offsets or indices. These prelinked values include "vtaboff" (vtable offset), "fieldoff" (field offset), and "iface" (interface pool index).
In the cases where a format value isn't explictly part of the syntax but instead picks a variant, each variant is listed with the prefix "[X=N]" (e.g., "[B=2]") to indicate the correspondence.

The Formats

FormatIDSyntaxNotable Opcodes Covered
ØØ|op10xop 
B|A|op12xop vA, vB 
11nop vA, #+B 
AA|op11xop vAA 
10top +AAgoto
ØØ|op AAAA20top +AAAAgoto/16
AA|op BBBB22xop vAA, vBBBB 
21top vAA, +BBBB 
21sop vAA, #+BBBB 
21hop vAA, #+BBBB0000
op vAA, #+BBBB000000000000
 
21cop vAA, type@BBBB
op vAA, field@BBBB
op vAA, string@BBBB
check-cast
const-class
const-string
AA|op CC|BB23xop vAA, vBB, vCC 
22bop vAA, vBB, #+CC 
B|A|op CCCC22top vA, vB, +CCCC 
22sop vA, vB, #+CCCC 
22cop vA, vB, type@CCCC
op vA, vB, field@CCCC
instance-of
22csop vA, vB, fieldoff@CCCC(suggested format for statically linked field access instructions of format 22c)
ØØ|op AAAAlo AAAAhi30top +AAAAAAAAgoto/32
ØØ|op AAAA BBBB32xop vAAAA, vBBBB 
AA|op BBBBlo BBBBhi31iop vAA, #+BBBBBBBB 
31top vAA, +BBBBBBBB 
31cop vAA, string@BBBBBBBBconst-string/jumbo
B|A|op CCCC G|F|E|D35c[B=5op {vD, vE, vF, vG, vA}, meth@CCCC
[B=5op {vD, vE, vF, vG, vA}, type@CCCC
[B=4op {vD, vE, vF, vG}, kind@CCCC
[B=3op {vD, vE, vF}, kind@CCCC
[B=2op {vD, vE}, kind@CCCC
[B=1op {vD}, kind@CCCC
[B=0op {}, kind@CCCC
 
B|A|op CCCC G|F|E|D35ms[B=5op {vD, vE, vF, vG, vA}, vtaboff@CCCC
[B=4op {vD, vE, vF, vG}, vtaboff@CCCC
[B=3op {vD, vE, vF}, vtaboff@CCCC
[B=2op {vD, vE}, vtaboff@CCCC
[B=1op {vD}, vtaboff@CCCC
(suggested format for statically linkedinvoke-virtual and invoke-superinstructions of format 35c)
B|A|op DDCC H|G|F|E35fs[B=5op {vE, vF, vG, vH, vA}, vtaboff@CC, iface@DD
[B=4op {vE, vF, vG, vH}, vtaboff@CC, iface@DD
[B=3op {vE, vF, vG}, vtaboff@CC, iface@DD
[B=2op {vE, vF}, vtaboff@CC, iface@DD
[B=1op {vE}, vtaboff@CC, iface@DD
(suggested format for statically linkedinvoke-interface instructions of format 35c)
AA|op BBBB CCCC3rcop {vCCCC .. vNNNN}, meth@BBBB
op {vCCCC .. vNNNN}, type@BBBB
(where NNNN = CCCC+AA-1, that is A determines the count 0..255, and C determines the first register)
 
AA|op BBBB CCCC3rmsop {vCCCC .. vNNNN}, vtaboff@BBBB
(where NNNN = CCCC+AA-1, that is A determines the count 0..255, and C determines the first register)
(suggested format for statically linkedinvoke-virtual and invoke-superinstructions of format 3rc)
AA|op CCBB DDDD3rfsop {vDDDD .. vNNNN}, vtaboff@BB, iface@CC
(where NNNN = DDDD+AA-1, that is A determines the count 0..255, and D determines the first register)
(suggested format for statically linkedinvoke-interface instructions of format3rc)
AA|op BBBBlo BBBB BBBB BBBBhi51lop vAA, #+BBBBBBBBBBBBBBBBconst-wide