1 <html devsite> 2 <head> 3 <title>Dalvik Executable instruction formats</title> 4 <meta name="project_path" value="/_project.yaml" /> 5 <meta name="book_path" value="/_book.yaml" /> 6 </head> 7 <body> 8 <!-- 9 Copyright 2017 The Android Open Source Project 10 11 Licensed under the Apache License, Version 2.0 (the "License"); 12 you may not use this file except in compliance with the License. 13 You may obtain a copy of the License at 14 15 http://www.apache.org/licenses/LICENSE-2.0 16 17 Unless required by applicable law or agreed to in writing, software 18 distributed under the License is distributed on an "AS IS" BASIS, 19 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 See the License for the specific language governing permissions and 21 limitations under the License. 22 --> 23 24 25 26 <p>This page lists the instruction formats used by the Dalvik Executable 27 format and Dalvik bytecode. It is meant to be used in conjunction with the 28 <a href="dalvik-bytecode.html">bytecode reference document</a>.</p> 29 30 <h2 id="bitwise">Bitwise descriptions</h2> 31 32 <p>The first column in the format table lists the bitwise layout of 33 the format. It consists of one or more space-separated "words" each of 34 which describes a 16-bit code unit. Each character in a word 35 represents four bits, read from high bits to low, with vertical bars 36 ("<code>|</code>") interspersed to aid in reading. Uppercase letters 37 in sequence from "<code>A</code>" are used to indicate fields within 38 the format (which then get defined further by the syntax column). The term 39 "<code>op</code>" is used to indicate the position of an eight-bit 40 opcode within the format. A slashed zero 41 ("<code>Ø</code>") is used to indicate that all bits must be 42 zero in the indicated position.</p> 43 44 <p>For the most part, lettering proceeds from earlier code units to 45 later code units, and low-order to high-order within a code unit. 46 However, there are a few exceptions to this general rule, which are 47 done in order to make the naming of similar-meaning parts be the same 48 across different instruction formats. These cases are noted explicitly 49 in the format descriptions.</p> 50 51 <p>For example, the format "<code>B|A|<i>op</i> CCCC</code>" indicates 52 that the format consists of two 16-bit code units. The first word 53 consists of the opcode in the low eight bits and a pair of four-bit 54 values in the high eight bits; and the second word consists of a single 55 16-bit value.</p> 56 57 <h2 id="format-ids">Format IDs</h2> 58 59 <p>The second column in the format table indicates the short identifier 60 for the format, which is used in other documents and in code to identify 61 the format.</p> 62 63 <p>Most format IDs consist of three characters, two digits followed by a 64 letter. The first digit indicates the number of 16-bit code units in the 65 format. The second digit indicates the maximum number of registers that the 66 format contains (maximum, since some formats can accommodate a variable 67 number of registers), with the special designation "<code>r</code>" indicating 68 that a range of registers is encoded. The final letter semi-mnemonically 69 indicates the type of any extra data encoded by the format. For example, 70 format "<code>21t</code>" is of length two, contains one register reference, 71 and additionally contains a branch target.</p> 72 73 <p>Suggested static linking formats have an additional 74 "<code>s</code>" suffix, making them four characters total. Similarly, 75 suggested "inline" linking formats have an additional "<code>i</code>" 76 suffix. (In this context, inline linking is like static linking, 77 except with more direct ties into a machine's implementation.) 78 Finally, a couple oddball suggested formats (e.g., 79 "<code>20bc</code>") include two pieces of data which are both 80 represented in its format ID.</p> 81 82 <p>The full list of typecode letters are as follows. Note that some 83 forms have different sizes, depending on the format:</p> 84 85 <table class="letters"> 86 <thead> 87 <tr> 88 <th>Mnemonic</th> 89 <th>Bit Sizes</th> 90 <th>Meaning</th> 91 </tr> 92 </thead> 93 <tbody> 94 <tr> 95 <td>b</td> 96 <td>8</td> 97 <td>immediate signed <b>b</b>yte</td> 98 </tr> 99 <tr> 100 <td>c</td> 101 <td>16, 32</td> 102 <td><b>c</b>onstant pool index</td> 103 </tr> 104 <tr> 105 <td>f</td> 106 <td>16</td> 107 <td>inter<b>f</b>ace constants (only used in statically linked formats) 108 </td> 109 </tr> 110 <tr> 111 <td>h</td> 112 <td>16</td> 113 <td>immediate signed <b>h</b>at (high-order bits of a 32- or 64-bit 114 value; low-order bits are all <code>0</code>) 115 </td> 116 </tr> 117 <tr> 118 <td>i</td> 119 <td>32</td> 120 <td>immediate signed <b>i</b>nt, or 32-bit float</td> 121 </tr> 122 <tr> 123 <td>l</td> 124 <td>64</td> 125 <td>immediate signed <b>l</b>ong, or 64-bit double</td> 126 </tr> 127 <tr> 128 <td>m</td> 129 <td>16</td> 130 <td><b>m</b>ethod constants (only used in statically linked formats)</td> 131 </tr> 132 <tr> 133 <td>n</td> 134 <td>4</td> 135 <td>immediate signed <b>n</b>ibble</td> 136 </tr> 137 <tr> 138 <td>s</td> 139 <td>16</td> 140 <td>immediate signed <b>s</b>hort</td> 141 </tr> 142 <tr> 143 <td>t</td> 144 <td>8, 16, 32</td> 145 <td>branch <b>t</b>arget</td> 146 </tr> 147 <tr> 148 <td>x</td> 149 <td>0</td> 150 <td>no additional data</td> 151 </tr> 152 </tbody> 153 </table> 154 155 <h2 id="syntax">Syntax</h2> 156 157 <p>The third column of the format table indicates the human-oriented 158 syntax for instructions which use the indicated format. Each instruction 159 starts with the named opcode and is optionally followed by one or 160 more arguments, themselves separated with commas.</p> 161 162 <p>Wherever an argument refers to a field from the first column, the 163 letter for that field is indicated in the syntax, repeated once for 164 each four bits of the field. For example, an eight-bit field labeled 165 "<code>BB</code>" in the first column would also be labeled 166 "<code>BB</code>" in the syntax column.</p> 167 168 <p>Arguments which name a register have the form "<code>v<i>X</i></code>". 169 The prefix "<code>v</code>" was chosen instead of the more common 170 "<code>r</code>" exactly to avoid conflicting with (non-virtual) architectures 171 on which the Dalvik Executable format might be implemented which themselves 172 use the prefix "<code>r</code>" for their registers. (That is, this 173 decision makes it possible to talk about both virtual and real registers 174 together without the need for circumlocution.)</p> 175 176 <p>Arguments which indicate a literal value have the form 177 "<code>#+<i>X</i></code>". Some formats indicate literals that only 178 have non-zero bits in their high-order bits; for these, the zeroes 179 are represented explicitly in the syntax, even though they do not 180 appear in the bitwise representation.</p> 181 182 <p>Arguments which indicate a relative instruction address offset have the 183 form "<code>+<i>X</i></code>".</p> 184 185 <p>Arguments which indicate a literal constant pool index have the form 186 "<code><i>kind</i>@<i>X</i></code>", where "<code><i>kind</i></code>" 187 indicates which constant pool is being referred to. Each opcode that 188 uses such a format explicitly allows only one kind of constant; see 189 the opcode reference to figure out the correspondence. The 190 kinds of constant pool are "<code>string</code>" (string pool index), 191 "<code>type</code>" (type pool index), "<code>field</code>" (field 192 pool index), "<code>meth</code>" (method pool index), and 193 "<code>site</code>" (call site index).</p> 194 195 <p>Similar to the representation of constant pool indices, there are 196 also suggested (optional) forms that indicate prelinked offsets or 197 indices. There are two types of suggested prelinked value: vtable offsets 198 (indicated as "<code>vtaboff</code>") and field offsets (indicated as 199 "<code>fieldoff</code>").</p> 200 201 <p>In the cases where a format value isn't explicitly part of the syntax 202 but instead picks a variant, each variant is listed with the prefix 203 "<code>[<i>X</i>=<i>N</i>]</code>" (e.g., "<code>[A=2]</code>") to indicate 204 the correspondence.</p> 205 206 <h2 id="formats">The formats</h2> 207 208 <table class="format"> 209 <thead> 210 <tr> 211 <th>Format</th> 212 <th>ID</th> 213 <th>Syntax</th> 214 <th>Notable Opcodes Covered</th> 215 </tr> 216 </thead> 217 <tbody> 218 <tr> 219 <td><i>N/A</i></td> 220 <td>00x</td> 221 <td><i><code>N/A</code></i></td> 222 <td><i>pseudo-format used for unused opcodes; suggested for use as the 223 nominal format for a breakpoint opcode</i></td> 224 </tr> 225 <tr> 226 <td>ØØ|<i>op</i></td> 227 <td>10x</td> 228 <td><i><code>op</code></i></td> 229 <td> </td> 230 </tr> 231 <tr> 232 <td rowspan="2">B|A|<i>op</i></td> 233 <td>12x</td> 234 <td><i><code>op</code></i> vA, vB</td> 235 <td> </td> 236 </tr> 237 <tr> 238 <td>11n</td> 239 <td><i><code>op</code></i> vA, #+B</td> 240 <td> </td> 241 </tr> 242 <tr> 243 <td rowspan="2">AA|<i>op</i></td> 244 <td>11x</td> 245 <td><i><code>op</code></i> vAA</td> 246 <td> </td> 247 </tr> 248 <tr> 249 <td>10t</td> 250 <td><i><code>op</code></i> +AA</td> 251 <td>goto</td> 252 </tr> 253 <tr> 254 <td>ØØ|<i>op</i> AAAA</td></td> 255 <td>20t</td> 256 <td><i><code>op</code></i> +AAAA</td> 257 <td>goto/16</td> 258 </tr> 259 <tr> 260 <td>AA|<i>op</i> BBBB</td></td> 261 <td>20bc</td> 262 <td><i><code>op</code></i> AA, kind@BBBB</td> 263 <td><i>suggested format for statically determined verification errors; 264 A is the type of error and B is an index into a type-appropriate 265 table (e.g. method references for a no-such-method error)</i></td> 266 </tr> 267 <tr> 268 <td rowspan="5">AA|<i>op</i> BBBB</td> 269 <td>22x</td> 270 <td><i><code>op</code></i> vAA, vBBBB</td> 271 <td> </td> 272 </tr> 273 <tr> 274 <td>21t</td> 275 <td><i><code>op</code></i> vAA, +BBBB</td> 276 <td> </td> 277 </tr> 278 <tr> 279 <td>21s</td> 280 <td><i><code>op</code></i> vAA, #+BBBB</td> 281 <td> </td> 282 </tr> 283 <tr> 284 <td>21h</td> 285 <td><i><code>op</code></i> vAA, #+BBBB0000<br/> 286 <i><code>op</code></i> vAA, #+BBBB000000000000 287 </td> 288 <td> </td> 289 </tr> 290 <tr> 291 <td>21c</td> 292 <td><i><code>op</code></i> vAA, type@BBBB<br/> 293 <i><code>op</code></i> vAA, field@BBBB<br/> 294 <i><code>op</code></i> vAA, string@BBBB 295 </td> 296 <td>check-cast<br/> 297 const-class<br/> 298 const-string 299 </td> 300 </tr> 301 <tr> 302 <td rowspan="2">AA|<i>op</i> CC|BB</td> 303 <td>23x</td> 304 <td><i><code>op</code></i> vAA, vBB, vCC</td> 305 <td> </td> 306 </tr> 307 <tr> 308 <td>22b</td> 309 <td><i><code>op</code></i> vAA, vBB, #+CC</td> 310 <td> </td> 311 </tr> 312 <tr> 313 <td rowspan="4">B|A|<i>op</i> CCCC</td> 314 <td>22t</td> 315 <td><i><code>op</code></i> vA, vB, +CCCC</td> 316 <td> </td> 317 </tr> 318 <tr> 319 <td>22s</td> 320 <td><i><code>op</code></i> vA, vB, #+CCCC</td> 321 <td> </td> 322 </tr> 323 <tr> 324 <td>22c</td> 325 <td><i><code>op</code></i> vA, vB, type@CCCC<br/> 326 <i><code>op</code></i> vA, vB, field@CCCC 327 </td> 328 <td>instance-of</td> 329 </tr> 330 <tr> 331 <td>22cs</td> 332 <td><i><code>op</code></i> vA, vB, fieldoff@CCCC</td> 333 <td><i>suggested format for statically linked field access instructions of 334 format 22c</i> 335 </td> 336 </tr> 337 <tr> 338 <td>ØØ|<i>op</i> AAAA<sub>lo</sub> AAAA<sub>hi</sub></td></td> 339 <td>30t</td> 340 <td><i><code>op</code></i> +AAAAAAAA</td> 341 <td>goto/32</td> 342 </tr> 343 <tr> 344 <td>ØØ|<i>op</i> AAAA BBBB</td> 345 <td>32x</td> 346 <td><i><code>op</code></i> vAAAA, vBBBB</td> 347 <td> </td> 348 </tr> 349 <tr> 350 <td rowspan="3">AA|<i>op</i> BBBB<sub>lo</sub> BBBB<sub>hi</sub></td> 351 <td>31i</td> 352 <td><i><code>op</code></i> vAA, #+BBBBBBBB</td> 353 <td> </td> 354 </tr> 355 <tr> 356 <td>31t</td> 357 <td><i><code>op</code></i> vAA, +BBBBBBBB</td> 358 <td> </td> 359 </tr> 360 <tr> 361 <td>31c</td> 362 <td><i><code>op</code></i> vAA, string@BBBBBBBB</td> 363 <td>const-string/jumbo</td> 364 </tr> 365 <tr> 366 <td rowspan="3">A|G|<i>op</i> BBBB F|E|D|C</td> 367 <td>35c</td> 368 <td><i>[<code>A=5</code>] <code>op</code></i> {vC, vD, vE, vF, vG}, 369 meth@BBBB<br/> 370 <i>[<code>A=5</code>] <code>op</code></i> {vC, vD, vE, vF, vG}, 371 site@BBBB<br/> 372 <i>[<code>A=5</code>] <code>op</code></i> {vC, vD, vE, vF, vG}, 373 type@BBBB<br/> 374 <i>[<code>A=4</code>] <code>op</code></i> {vC, vD, vE, vF}, 375 <i><code>kind</code></i>@BBBB<br/> 376 <i>[<code>A=3</code>] <code>op</code></i> {vC, vD, vE}, 377 <i><code>kind</code></i>@BBBB<br/> 378 <i>[<code>A=2</code>] <code>op</code></i> {vC, vD}, 379 <i><code>kind</code></i>@BBBB<br/> 380 <i>[<code>A=1</code>] <code>op</code></i> {vC}, 381 <i><code>kind</code></i>@BBBB<br/> 382 <i>[<code>A=0</code>] <code>op</code></i> {}, 383 <i><code>kind</code></i>@BBBB<br/> 384 <p><i>The unusual choice in lettering here reflects a desire to make 385 the count and the reference index have the same label as in format 386 3rc.</i></p> 387 </td> 388 <td> </td> 389 </tr> 390 <tr> 391 <td>35ms</td> 392 <td><i>[<code>A=5</code>] <code>op</code></i> {vC, vD, vE, vF, vG}, 393 vtaboff@BBBB<br/> 394 <i>[<code>A=4</code>] <code>op</code></i> {vC, vD, vE, vF}, 395 vtaboff@BBBB<br/> 396 <i>[<code>A=3</code>] <code>op</code></i> {vC, vD, vE}, 397 vtaboff@BBBB<br/> 398 <i>[<code>A=2</code>] <code>op</code></i> {vC, vD}, 399 vtaboff@BBBB<br/> 400 <i>[<code>A=1</code>] <code>op</code></i> {vC}, 401 vtaboff@BBBB<br/> 402 <p><i>The unusual choice in lettering here reflects a desire to make 403 the count and the reference index have the same label as in format 404 3rms.</i></p> 405 </td> 406 <td><i>suggested format for statically linked <code>invoke-virtual</code> 407 and <code>invoke-super</code> instructions of format 35c</i> 408 </td> 409 </tr> 410 <tr> 411 <td>35mi</td> 412 <td><i>[<code>A=5</code>] <code>op</code></i> {vC, vD, vE, vF, vG}, 413 inline@BBBB<br/> 414 <i>[<code>A=4</code>] <code>op</code></i> {vC, vD, vE, vF}, 415 inline@BBBB<br/> 416 <i>[<code>A=3</code>] <code>op</code></i> {vC, vD, vE}, 417 inline@BBBB<br/> 418 <i>[<code>A=2</code>] <code>op</code></i> {vC, vD}, 419 inline@BBBB<br/> 420 <i>[<code>A=1</code>] <code>op</code></i> {vC}, 421 inline@BBBB<br/> 422 <p><i>The unusual choice in lettering here reflects a desire to make 423 the count and the reference index have the same label as in format 424 3rmi.</i></p> 425 </td> 426 <td><i>suggested format for inline linked <code>invoke-static</code> 427 and <code>invoke-virtual</code> instructions of format 35c</i> 428 </td> 429 </tr> 430 <tr> 431 <td rowspan="3">AA|<i>op</i> BBBB CCCC</td> 432 <td>3rc</td> 433 <td><i><code>op</code></i> {vCCCC .. vNNNN}, meth@BBBB<br/> 434 <i><code>op</code></i> {vCCCC .. vNNNN}, site@BBBB<br/> 435 <i><code>op</code></i> {vCCCC .. vNNNN}, type@BBBB<br/> 436 <p><i>where <code>NNNN = CCCC+AA-1</code>, that is <code>A</code> 437 determines the count <code>0..255</code>, and <code>C</code> 438 determines the first register</i></p> 439 </td> 440 <td> </td> 441 </tr> 442 <tr> 443 <td>3rms</td> 444 <td><i><code>op</code></i> {vCCCC .. vNNNN}, vtaboff@BBBB<br/> 445 <p><i>where <code>NNNN = CCCC+AA-1</code>, that is <code>A</code> 446 determines the count <code>0..255</code>, and <code>C</code> 447 determines the first register</i></p> 448 </td> 449 <td><i>suggested format for statically linked <code>invoke-virtual</code> 450 and <code>invoke-super</code> instructions of format <code>3rc</code></i> 451 </td> 452 </tr> 453 <tr> 454 <td>3rmi</td> 455 <td><i><code>op</code></i> {vCCCC .. vNNNN}, inline@BBBB<br/> 456 <p><i>where <code>NNNN = CCCC+AA-1</code>, that is <code>A</code> 457 determines the count <code>0..255</code>, and <code>C</code> 458 determines the first register</i></p> 459 </td> 460 <td><i>suggested format for inline linked <code>invoke-static</code> 461 and <code>invoke-virtual</code> instructions of format 3rc</i> 462 </td> 463 </tr> 464 <tr> 465 <td>A|G|<i>op</i> BBBB F|E|D|C HHHH 466 <td>45cc</td> 467 <td> 468 <i>[<code>A=5</code>] <code>op</code></i> {vC, vD, vE, vF, vG}, meth@BBBB, proto@HHHH<br> 469 <i>[<code>A=4</code>] <code>op</code></i> {vC, vD, vE, vF}, meth@BBBB, proto@HHHH<br> 470 <i>[<code>A=3</code>] <code>op</code></i> {vC, vD, vE}, meth@BBBB, proto@HHHH<br> 471 <i>[<code>A=2</code>] <code>op</code></i> {vC, vD}, meth@BBBB, proto@HHHH<br> 472 <i>[<code>A=1</code>] <code>op</code></i> {vC}, meth@BBBB, proto@HHHH 473 </td> 474 <td>invoke-polymorphic 475 </td> 476 </tr> 477 <tr> 478 <td>AA|<i>op</i> BBBB CCCC HHHH 479 <td>4rcc</td> 480 <td> 481 <code>op></code> {vCCCC .. vNNNN}, meth@BBBB, proto@HHHH 482 <p><i>wheere <code>NNNN = CCCC+AA-1</code>, that is <code>A</code> 483 determines the count <code>0..255</code>, and <code>C</code> 484 determines the first register</i></p> 485 </td> 486 <td>invoke-polymorphic/range 487 </td> 488 </tr> 489 <tr> 490 <td>AA|<i>op</i> BBBB<sub>lo</sub> BBBB BBBB BBBB<sub>hi</sub></td> 491 <td>51l</td> 492 <td><i><code>op</code></i> vAA, #+BBBBBBBBBBBBBBBB</td> 493 <td>const-wide</td> 494 </tr> 495 </tbody> 496 </table> 497 498 </body> 499 </html> 500