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