1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
6 <title>Bytecode for the Dalvik VM</title>
7 <link rel=stylesheet href="dalvik-bytecode.css">
12 <h1>Bytecode for the Dalvik VM</h1>
13 <p>Copyright © 2007 The Android Open Source Project
15 <h2>General Design</h2>
18 <li>The machine model and calling conventions are meant to approximately
19 imitate common real architectures and C-style calling conventions:
21 <li>The VM is register-based, and frames are fixed in size upon creation.
22 Each frame consists of a particular number of registers (specified by
23 the method) as well as any adjunct data needed to execute the method,
24 such as (but not limited to) the program counter and a reference to the
25 <code>.dex</code> file that contains the method.
27 <li>Registers are 32 bits wide. Adjacent register pairs are used for 64-bit
30 <li>In terms of bitwise representation, <code>(Object) null == (int)
33 <li>The <i>N</i> arguments to a method land in the last <i>N</i> registers
34 of the method's invocation frame, in order. Wide arguments consume
35 two registers. Instance methods are passed a <code>this</code> reference
36 as their first argument.
39 <li>The storage unit in the instruction stream is a 16-bit unsigned quantity.
40 Some bits in some instructions are ignored / must-be-zero.
42 <li>Instructions aren't gratuitously limited to a particular type. For
43 example, instructions that move 32-bit register values without interpretation
44 don't have to specify whether they are moving ints or floats.
46 <li>There are separately enumerated and indexed constant pools for
47 references to strings, types, fields, and methods.
49 <li>Bitwise literal data is represented in-line in the instruction stream.</li>
50 <li>Because, in practice, it is uncommon for a method to need more than
51 16 registers, and because needing more than eight registers <i>is</i>
52 reasonably common, many instructions may only address the first 16
53 registers. When reasonably possible, instructions allow references to
54 up to the first 256 registers. In cases where an instruction variant isn't
55 available to address a desired register, it is expected that the register
56 contents get moved from the original register to a low register (before the
57 operation) and/or moved from a low result register to a high register
58 (after the operation).
60 <li>There are several "pseudo-instructions" that are used to hold
61 variable-length data referred to by regular instructions (for example,
62 <code>fill-array-data</code>). Such instructions must never be
63 encountered during the normal flow of execution. In addition, the
64 instructions must be located on even-numbered bytecode offsets (that is,
65 4-byte aligned). In order to meet this requirement, dex generation tools
66 should emit an extra <code>nop</code> instruction as a spacer if such an
67 instruction would otherwise be unaligned. Finally, though not required,
68 it is expected that most tools will choose to emit these instructions at
69 the ends of methods, since otherwise it would likely be the case that
70 additional instructions would be needed to branch around them.
72 <li>When installed on a running system, some instructions may be altered,
73 changing their format, as an install-time static linking optimization.
74 This is to allow for faster execution once linkage is known.
76 <a href="instruction-formats.html">instruction formats document</a>
77 for the suggested variants. The word "suggested" is used advisedly;
78 it is not mandatory to implement these.
80 <li>Human-syntax and mnemonics:
82 <li>Dest-then-source ordering for arguments.</li>
83 <li>Some opcodes have a disambiguating suffix with respect to the type(s)
84 they operate on: Type-general 64-bit opcodes
85 are suffixed with <code>-wide</code>.
86 Type-specific opcodes are suffixed with their type (or a
87 straightforward abbreviation), one of: <code>-boolean</code>
88 <code>-byte</code> <code>-char</code> <code>-short</code>
89 <code>-int</code> <code>-long</code> <code>-float</code>
90 <code>-double</code> <code>-object</code> <code>-string</code>
91 <code>-class</code> <code>-void</code>. Type-general 32-bit opcodes
94 <li>Some opcodes have a disambiguating suffix to distinguish
95 otherwise-identical operations that have different instruction layouts
96 or options. These suffixes are separated from the main names with a slash
97 ("<code>/</code>") and mainly exist at all to make there be a one-to-one
98 mapping with static constants in the code that generates and interprets
99 executables (that is, to reduce ambiguity for humans).
103 <li>See the <a href="instruction-formats.html">instruction formats
104 document</a> for more details about the various instruction formats
105 (listed under "Op & Format") as well as details about the opcode
110 <h2>Summary of Instruction Set</h2>
112 <table class="instruc">
115 <th>Op & Format</th>
116 <th>Mnemonic / Syntax</th>
126 <td>Waste cycles.</td>
131 <td><code>A:</code> destination register (4 bits)<br/>
132 <code>B:</code> source register (4 bits)</td>
133 <td>Move the contents of one non-object register to another.</td>
137 <td>move/from16 vAA, vBBBB</td>
138 <td><code>A:</code> destination register (8 bits)<br/>
139 <code>B:</code> source register (16 bits)</td>
140 <td>Move the contents of one non-object register to another.</td>
144 <td>move/16 vAAAA, vBBBB</td>
145 <td><code>A:</code> destination register (16 bits)<br/>
146 <code>B:</code> source register (16 bits)</td>
147 <td>Move the contents of one non-object register to another.</td>
151 <td>move-wide vA, vB</td>
152 <td><code>A:</code> destination register pair (4 bits)<br/>
153 <code>B:</code> source register pair (4 bits)</td>
154 <td>Move the contents of one register-pair to another.
156 It is legal to move from <code>v<i>N</i></code> to either
157 <code>v<i>N-1</i></code> or <code>v<i>N+1</i></code>, so implementations
158 must arrange for both halves of a register pair to be read before
159 anything is written.</p>
164 <td>move-wide/from16 vAA, vBBBB</td>
165 <td><code>A:</code> destination register pair (8 bits)<br/>
166 <code>B:</code> source register pair (16 bits)</td>
167 <td>Move the contents of one register-pair to another.
169 Implementation considerations are the same as <code>move-wide</code>,
175 <td>move-wide/16 vAAAA, vBBBB</td>
176 <td><code>A:</code> destination register pair (16 bits)<br/>
177 <code>B:</code> source register pair (16 bits)</td>
178 <td>Move the contents of one register-pair to another.
180 Implementation considerations are the same as <code>move-wide</code>,
186 <td>move-object vA, vB</td>
187 <td><code>A:</code> destination register (4 bits)<br/>
188 <code>B:</code> source register (4 bits)</td>
189 <td>Move the contents of one object-bearing register to another.</td>
193 <td>move-object/from16 vAA, vBBBB</td>
194 <td><code>A:</code> destination register (8 bits)<br/>
195 <code>B:</code> source register (16 bits)</td>
196 <td>Move the contents of one object-bearing register to another.</td>
200 <td>move-object/16 vAAAA, vBBBB</td>
201 <td><code>A:</code> destination register (16 bits)<br/>
202 <code>B:</code> source register (16 bits)</td>
203 <td>Move the contents of one object-bearing register to another.</td>
207 <td>move-result vAA</td>
208 <td><code>A:</code> destination register (8 bits)</td>
209 <td>Move the single-word non-object result of the most recent
210 <code>invoke-<i>kind</i></code> into the indicated register.
211 This must be done as the instruction immediately after an
212 <code>invoke-<i>kind</i></code> whose (single-word, non-object) result
213 is not to be ignored; anywhere else is invalid.</td>
217 <td>move-result-wide vAA</td>
218 <td><code>A:</code> destination register pair (8 bits)</td>
219 <td>Move the double-word result of the most recent
220 <code>invoke-<i>kind</i></code> into the indicated register pair.
221 This must be done as the instruction immediately after an
222 <code>invoke-<i>kind</i></code> whose (double-word) result
223 is not to be ignored; anywhere else is invalid.</td>
227 <td>move-result-object vAA</td>
228 <td><code>A:</code> destination register (8 bits)</td>
229 <td>Move the object result of the most recent <code>invoke-<i>kind</i></code>
230 into the indicated register. This must be done as the instruction
231 immediately after an <code>invoke-<i>kind</i></code> or
232 <code>filled-new-array</code>
233 whose (object) result is not to be ignored; anywhere else is invalid.</td>
237 <td>move-exception vAA</td>
238 <td><code>A:</code> destination register (8 bits)</td>
239 <td>Save a just-caught exception into the given register. This should
240 be the first instruction of any exception handler whose caught
241 exception is not to be ignored, and this instruction may <i>only</i>
242 ever occur as the first instruction of an exception handler; anywhere
243 else is invalid.</td>
249 <td>Return from a <code>void</code> method.</td>
254 <td><code>A:</code> return value register (8 bits)</td>
255 <td>Return from a single-width (32-bit) non-object value-returning
261 <td>return-wide vAA</td>
262 <td><code>A:</code> return value register-pair (8 bits)</td>
263 <td>Return from a double-width (64-bit) value-returning method.</td>
267 <td>return-object vAA</td>
268 <td><code>A:</code> return value register (8 bits)</td>
269 <td>Return from an object-returning method.</td>
273 <td>const/4 vA, #+B</td>
274 <td><code>A:</code> destination register (4 bits)<br/>
275 <code>B:</code> signed int (4 bits)</td>
276 <td>Move the given literal value (sign-extended to 32 bits) into
277 the specified register.</td>
281 <td>const/16 vAA, #+BBBB</td>
282 <td><code>A:</code> destination register (8 bits)<br/>
283 <code>B:</code> signed int (16 bits)</td>
284 <td>Move the given literal value (sign-extended to 32 bits) into
285 the specified register.</td>
289 <td>const vAA, #+BBBBBBBB</td>
290 <td><code>A:</code> destination register (8 bits)<br/>
291 <code>B:</code> arbitrary 32-bit constant</td>
292 <td>Move the given literal value into the specified register.</td>
296 <td>const/high16 vAA, #+BBBB0000</td>
297 <td><code>A:</code> destination register (8 bits)<br/>
298 <code>B:</code> signed int (16 bits)</td>
299 <td>Move the given literal value (right-zero-extended to 32 bits) into
300 the specified register.</td>
304 <td>const-wide/16 vAA, #+BBBB</td>
305 <td><code>A:</code> destination register (8 bits)<br/>
306 <code>B:</code> signed int (16 bits)</td>
307 <td>Move the given literal value (sign-extended to 64 bits) into
308 the specified register-pair.</td>
312 <td>const-wide/32 vAA, #+BBBBBBBB</td>
313 <td><code>A:</code> destination register (8 bits)<br/>
314 <code>B:</code> signed int (32 bits)</td>
315 <td>Move the given literal value (sign-extended to 64 bits) into
316 the specified register-pair.</td>
320 <td>const-wide vAA, #+BBBBBBBBBBBBBBBB</td>
321 <td><code>A:</code> destination register (8 bits)<br/>
322 <code>B:</code> arbitrary double-width (64-bit) constant</td>
323 <td>Move the given literal value into
324 the specified register-pair.</td>
328 <td>const-wide/high16 vAA, #+BBBB000000000000</td>
329 <td><code>A:</code> destination register (8 bits)<br/>
330 <code>B:</code> signed int (16 bits)</td>
331 <td>Move the given literal value (right-zero-extended to 64 bits) into
332 the specified register-pair.</td>
336 <td>const-string vAA, string@BBBB</td>
337 <td><code>A:</code> destination register (8 bits)<br/>
338 <code>B:</code> string index</td>
339 <td>Move a reference to the string specified by the given index into the
340 specified register.</td>
344 <td>const-string/jumbo vAA, string@BBBBBBBB</td>
345 <td><code>A:</code> destination register (8 bits)<br/>
346 <code>B:</code> string index</td>
347 <td>Move a reference to the string specified by the given index into the
348 specified register.</td>
352 <td>const-class vAA, type@BBBB</td>
353 <td><code>A:</code> destination register (8 bits)<br/>
354 <code>B:</code> type index</td>
355 <td>Move a reference to the class specified by the given index into the
356 specified register. In the case where the indicated type is primitive,
357 this will store a reference to the primitive type's degenerate
362 <td>monitor-enter vAA</td>
363 <td><code>A:</code> reference-bearing register (8 bits)</td>
364 <td>Acquire the monitor for the indicated object.</td>
368 <td>monitor-exit vAA</td>
369 <td><code>A:</code> reference-bearing register (8 bits)</td>
370 <td>Release the monitor for the indicated object.
372 If this instruction needs to throw an exception, it must do
373 so as if the pc has already advanced past the instruction.
374 It may be useful to think of this as the instruction successfully
375 executing (in a sense), and the exception getting thrown <i>after</i>
376 the instruction but <i>before</i> the next one gets a chance to
377 run. This definition makes it possible for a method to use
378 a monitor cleanup catch-all (e.g., <code>finally</code>) block as
379 the monitor cleanup for that block itself, as a way to handle the
380 arbitrary exceptions that might get thrown due to the historical
381 implementation of <code>Thread.stop()</code>, while still managing
382 to have proper monitor hygiene.</p>
387 <td>check-cast vAA, type@BBBB</td>
388 <td><code>A:</code> reference-bearing register (8 bits)<br/>
389 <code>B:</code> type index (16 bits)</td>
390 <td>Throw a <code>ClassCastException</code> if the reference in the
391 given register cannot be cast to the indicated type.
392 <p><b>Note:</b> Since <code>A</code> must always be a reference
393 (and not a primitive value), this will necessarily fail at runtime
394 (that is, it will throw an exception) if <code>B</code> refers to a
400 <td>instance-of vA, vB, type@CCCC</td>
401 <td><code>A:</code> destination register (4 bits)<br/>
402 <code>B:</code> reference-bearing register (4 bits)<br/>
403 <code>C:</code> type index (16 bits)</td>
404 <td>Store in the given destination register <code>1</code>
405 if the indicated reference is an instance of the given type,
406 or <code>0</code> if not.
407 <p><b>Note:</b> Since <code>B</code> must always be a reference
408 (and not a primitive value), this will always result
409 in <code>0</code> being stored if <code>C</code> refers to a primitive
414 <td>array-length vA, vB</td>
415 <td><code>A:</code> destination register (4 bits)<br/>
416 <code>B:</code> array reference-bearing register (4 bits)</td>
417 <td>Store in the given destination register the length of the indicated
418 array, in entries</td>
422 <td>new-instance vAA, type@BBBB</td>
423 <td><code>A:</code> destination register (8 bits)<br/>
424 <code>B:</code> type index</td>
425 <td>Construct a new instance of the indicated type, storing a
426 reference to it in the destination. The type must refer to a
427 non-array class.</td>
431 <td>new-array vA, vB, type@CCCC</td>
432 <td><code>A:</code> destination register (8 bits)<br/>
433 <code>B:</code> size register<br/>
434 <code>C:</code> type index</td>
435 <td>Construct a new array of the indicated type and size. The type
436 must be an array type.</td>
440 <td>filled-new-array {vD, vE, vF, vG, vA}, type@CCCC</td>
441 <td><code>B:</code> array size and argument word count (4 bits)<br/>
442 <code>C:</code> type index (16 bits)<br/>
443 <code>D..G, A:</code> argument registers (4 bits each)</td>
444 <td>Construct an array of the given type and size, filling it with the
445 supplied contents. The type must be an array type. The array's
446 contents must be single-word (that is,
447 no arrays of <code>long</code> or <code>double</code>). The constructed
448 instance is stored as a "result" in the same way that the method invocation
449 instructions store their results, so the constructed instance must
450 be moved to a register with a subsequent
451 <code>move-result-object</code> instruction (if it is to be used).</td>
455 <td>filled-new-array/range {vCCCC .. vNNNN}, type@BBBB</td>
456 <td><code>A:</code> array size and argument word count (8 bits)<br/>
457 <code>B:</code> type index (16 bits)<br/>
458 <code>C:</code> first argument register (16 bits)<br/>
459 <code>N = A + C - 1</code></td>
460 <td>Construct an array of the given type and size, filling it with
461 the supplied contents. Clarifications and restrictions are the same
462 as <code>filled-new-array</code>, described above.</td>
466 <td>fill-array-data vAA, +BBBBBBBB <i>(with supplemental data as specified
467 below in "<code>fill-array-data</code> Format")</i></td>
468 <td><code>A:</code> array reference (8 bits)<br/>
469 <code>B:</code> signed "branch" offset to table data pseudo-instruction
472 <td>Fill the given array with the indicated data. The reference must be
473 to an array of primitives, and the data table must match it in type and
474 must contain no more elements than will fit in the array. That is,
475 the array may be larger than the table, and if so, only the initial
476 elements of the array are set, leaving the remainder alone.
482 <td><code>A:</code> exception-bearing register (8 bits)<br/></td>
483 <td>Throw the indicated exception.</td>
488 <td><code>A:</code> signed branch offset (8 bits)</td>
489 <td>Unconditionally jump to the indicated instruction.
491 The branch offset may not be <code>0</code>. (A spin
492 loop may be legally constructed either with <code>goto/32</code> or
493 by including a <code>nop</code> as a target before the branch.)</p>
498 <td>goto/16 +AAAA</td>
499 <td><code>A:</code> signed branch offset (16 bits)<br/></td>
500 <td>Unconditionally jump to the indicated instruction.
502 The branch offset may not be <code>0</code>. (A spin
503 loop may be legally constructed either with <code>goto/32</code> or
504 by including a <code>nop</code> as a target before the branch.)</p>
509 <td>goto/32 +AAAAAAAA</td>
510 <td><code>A:</code> signed branch offset (32 bits)<br/></td>
511 <td>Unconditionally jump to the indicated instruction.</td>
515 <td>packed-switch vAA, +BBBBBBBB <i>(with supplemental data as
516 specified below in "<code>packed-switch</code> Format")</i></td>
517 <td><code>A:</code> register to test<br/>
518 <code>B:</code> signed "branch" offset to table data pseudo-instruction
521 <td>Jump to a new instruction based on the value in the
522 given register, using a table of offsets corresponding to each value
523 in a particular integral range, or fall through to the next
524 instruction if there is no match.
529 <td>sparse-switch vAA, +BBBBBBBB <i>(with supplemental data as
530 specified below in "<code>sparse-switch</code> Format")</i></td>
531 <td><code>A:</code> register to test<br/>
532 <code>B:</code> signed "branch" offset to table data pseudo-instruction
535 <td>Jump to a new instruction based on the value in the given
536 register, using an ordered table of value-offset pairs, or fall
537 through to the next instruction if there is no match.
542 <td>cmp<i>kind</i> vAA, vBB, vCC<br/>
543 2d: cmpl-float <i>(lt bias)</i><br/>
544 2e: cmpg-float <i>(gt bias)</i><br/>
545 2f: cmpl-double <i>(lt bias)</i><br/>
546 30: cmpg-double <i>(gt bias)</i><br/>
549 <td><code>A:</code> destination register (8 bits)<br/>
550 <code>B:</code> first source register or pair<br/>
551 <code>C:</code> second source register or pair</td>
552 <td>Perform the indicated floating point or <code>long</code> comparison,
553 storing <code>0</code> if the two arguments are equal, <code>1</code>
554 if the second argument is larger, or <code>-1</code> if the first
555 argument is larger. The "bias" listed for the floating point operations
556 indicates how <code>NaN</code> comparisons are treated: "Gt bias"
557 instructions return <code>1</code> for <code>NaN</code> comparisons,
558 and "lt bias" instructions return
560 <p>For example, to check to see if floating point
561 <code>a < b</code>, then it is advisable to use
562 <code>cmpg-float</code>; a result of <code>-1</code> indicates that
563 the test was true, and the other values indicate it was false either
564 due to a valid comparison or because one or the other values was
565 <code>NaN</code>.</p>
570 <td>if-<i>test</i> vA, vB, +CCCC<br/>
578 <td><code>A:</code> first register to test (4 bits)<br/>
579 <code>B:</code> second register to test (4 bits)<br/>
580 <code>C:</code> signed branch offset (16 bits)</td>
581 <td>Branch to the given destination if the given two registers' values
582 compare as specified.
584 The branch offset may not be <code>0</code>. (A spin
585 loop may be legally constructed either by branching around a
586 backward <code>goto</code> or by including a <code>nop</code> as
587 a target before the branch.)</p>
592 <td>if-<i>test</i>z vAA, +BBBB<br/>
600 <td><code>A:</code> register to test (8 bits)<br/>
601 <code>B:</code> signed branch offset (16 bits)</td>
602 <td>Branch to the given destination if the given register's value compares
605 The branch offset may not be <code>0</code>. (A spin
606 loop may be legally constructed either by branching around a
607 backward <code>goto</code> or by including a <code>nop</code> as
608 a target before the branch.)</p>
613 <td><i>(unused)</i></td>
615 <td><i>(unused)</i></td>
619 <td><i>arrayop</i> vAA, vBB, vCC<br/>
623 47: aget-boolean<br/>
630 4e: aput-boolean<br/>
635 <td><code>A:</code> value register or pair; may be source or dest
637 <code>B:</code> array register (8 bits)<br/>
638 <code>C:</code> index register (8 bits)</td>
639 <td>Perform the identified array operation at the identified index of
640 the given array, loading or storing into the value register.</td>
644 <td>i<i>instanceop</i> vA, vB, field@CCCC<br/>
648 55: iget-boolean<br/>
655 5c: iput-boolean<br/>
660 <td><code>A:</code> value register or pair; may be source or dest
662 <code>B:</code> object register (4 bits)<br/>
663 <code>C:</code> instance field reference index (16 bits)</td>
664 <td>Perform the identified object instance field operation with
665 the identified field, loading or storing into the value register.
666 <p><b>Note:</b> These opcodes are reasonable candidates for static linking,
667 altering the field argument to be a more direct offset.</p>
672 <td>s<i>staticop</i> vAA, field@BBBB<br/>
676 63: sget-boolean<br/>
683 6a: sput-boolean<br/>
688 <td><code>A:</code> value register or pair; may be source or dest
690 <code>B:</code> static field reference index (16 bits)</td>
691 <td>Perform the identified object static field operation with the identified
692 static field, loading or storing into the value register.
693 <p><b>Note:</b> These opcodes are reasonable candidates for static linking,
694 altering the field argument to be a more direct offset.</p>
699 <td>invoke-<i>kind</i> {vD, vE, vF, vG, vA}, meth@CCCC<br/>
700 6e: invoke-virtual<br/>
701 6f: invoke-super<br/>
702 70: invoke-direct<br/>
703 71: invoke-static<br/>
706 <td><code>B:</code> argument word count (4 bits)<br/>
707 <code>C:</code> method index (16 bits)<br/>
708 <code>D..G, A:</code> argument registers (4 bits each)</td>
709 <td>Call the indicated method. The result (if any) may be stored
710 with an appropriate <code>move-result*</code> variant as the immediately
711 subsequent instruction.
712 <p><code>invoke-virtual</code> is used to invoke a normal virtual
713 method (a method that is not <code>static</code> or <code>final</code>,
714 and is not a constructor).</p>
715 <p><code>invoke-super</code> is used to invoke the closest superclass's
716 virtual method (as opposed to the one with the same <code>method_id</code>
717 in the calling class).</p>
718 <p><code>invoke-direct</code> is used to invoke a non-<code>static</code>
719 direct method (that is, an instance method that is by its nature
720 non-overridable, namely either a <code>private</code> instance method
721 or a constructor).</p>
722 <p><code>invoke-static</code> is used to invoke a <code>static</code>
723 method (which is always considered a direct method).</p>
724 <p><code>invoke-interface</code> is used to invoke an
725 <code>interface</code> method, that is, on an object whose concrete
726 class isn't known, using a <code>method_id</code> that refers to
727 an <code>interface</code>.</p>
728 <p><b>Note:</b> These opcodes are reasonable candidates for static linking,
729 altering the method argument to be a more direct offset
730 (or pair thereof).</p>
735 <td><i>(unused)</i></td>
737 <td><i>(unused)</i></td>
741 <td>invoke-<i>kind</i>/range {vCCCC .. vNNNN}, meth@BBBB<br/>
742 74: invoke-virtual/range<br/>
743 75: invoke-super/range<br/>
744 76: invoke-direct/range<br/>
745 77: invoke-static/range<br/>
746 78: invoke-interface/range
748 <td><code>A:</code> argument word count (8 bits)<br/>
749 <code>B:</code> method index (16 bits)<br/>
750 <code>C:</code> first argument register (16 bits)<br/>
751 <code>N = A + C - 1</code></td>
752 <td>Call the indicated method. See first <code>invoke-<i>kind</i></code>
753 description above for details, caveats, and suggestions.
758 <td><i>(unused)</i></td>
760 <td><i>(unused)</i></td>
764 <td><i>unop</i> vA, vB<br/>
772 82: int-to-float<br/>
773 83: int-to-double<br/>
775 85: long-to-float<br/>
776 86: long-to-double<br/>
777 87: float-to-int<br/>
778 88: float-to-long<br/>
779 89: float-to-double<br/>
780 8a: double-to-int<br/>
781 8b: double-to-long<br/>
782 8c: double-to-float<br/>
787 <td><code>A:</code> destination register or pair (4 bits)<br/>
788 <code>B:</code> source register or pair (4 bits)</td>
789 <td>Perform the identified unary operation on the source register,
790 storing the result in the destination register.</td>
795 <td><i>binop</i> vAA, vBB, vCC<br/>
829 <td><code>A:</code> destination register or pair (8 bits)<br/>
830 <code>B:</code> first source register or pair (8 bits)<br/>
831 <code>C:</code> second source register or pair (8 bits)</td>
832 <td>Perform the identified binary operation on the two source registers,
833 storing the result in the first source register.</td>
837 <td><i>binop</i>/2addr vA, vB<br/>
838 b0: add-int/2addr<br/>
839 b1: sub-int/2addr<br/>
840 b2: mul-int/2addr<br/>
841 b3: div-int/2addr<br/>
842 b4: rem-int/2addr<br/>
843 b5: and-int/2addr<br/>
844 b6: or-int/2addr<br/>
845 b7: xor-int/2addr<br/>
846 b8: shl-int/2addr<br/>
847 b9: shr-int/2addr<br/>
848 ba: ushr-int/2addr<br/>
849 bb: add-long/2addr<br/>
850 bc: sub-long/2addr<br/>
851 bd: mul-long/2addr<br/>
852 be: div-long/2addr<br/>
853 bf: rem-long/2addr<br/>
854 c0: and-long/2addr<br/>
855 c1: or-long/2addr<br/>
856 c2: xor-long/2addr<br/>
857 c3: shl-long/2addr<br/>
858 c4: shr-long/2addr<br/>
859 c5: ushr-long/2addr<br/>
860 c6: add-float/2addr<br/>
861 c7: sub-float/2addr<br/>
862 c8: mul-float/2addr<br/>
863 c9: div-float/2addr<br/>
864 ca: rem-float/2addr<br/>
865 cb: add-double/2addr<br/>
866 cc: sub-double/2addr<br/>
867 cd: mul-double/2addr<br/>
868 ce: div-double/2addr<br/>
871 <td><code>A:</code> destination and first source register or pair
873 <code>B:</code> second source register or pair (4 bits)</td>
874 <td>Perform the identified binary operation on the two source registers,
875 storing the result in the first source register.</td>
879 <td><i>binop</i>/lit16 vA, vB, #+CCCC<br/>
880 d0: add-int/lit16<br/>
881 d1: rsub-int (reverse subtract)<br/>
882 d2: mul-int/lit16<br/>
883 d3: div-int/lit16<br/>
884 d4: rem-int/lit16<br/>
885 d5: and-int/lit16<br/>
886 d6: or-int/lit16<br/>
889 <td><code>A:</code> destination register (4 bits)<br/>
890 <code>B:</code> source register (4 bits)<br/>
891 <code>C:</code> signed int constant (16 bits)</td>
892 <td>Perform the indicated binary op on the indicated register (first
893 argument) and literal value (second argument), storing the result in
894 the destination register.
896 <code>rsub-int</code> does not have a suffix since this version is the
897 main opcode of its family. Also, see below for details on its semantics.
903 <td><i>binop</i>/lit8 vAA, vBB, #+CC<br/>
904 d8: add-int/lit8<br/>
905 d9: rsub-int/lit8<br/>
906 da: mul-int/lit8<br/>
907 db: div-int/lit8<br/>
908 dc: rem-int/lit8<br/>
909 dd: and-int/lit8<br/>
911 df: xor-int/lit8<br/>
912 e0: shl-int/lit8<br/>
913 e1: shr-int/lit8<br/>
916 <td><code>A:</code> destination register (8 bits)<br/>
917 <code>B:</code> source register (8 bits)<br/>
918 <code>C:</code> signed int constant (8 bits)</td>
919 <td>Perform the indicated binary op on the indicated register (first
920 argument) and literal value (second argument), storing the result
921 in the destination register.
922 <p><b>Note:</b> See below for details on the semantics of
923 <code>rsub-int</code>.</p>
928 <td><i>(unused)</i></td>
930 <td><i>(unused)</i></td>
935 <h2><code>packed-switch</code> Format</h2>
937 <table class="supplement">
948 <td>ushort = 0x0100</td>
949 <td>identifying pseudo-opcode</td>
954 <td>number of entries in the table</td>
959 <td>first (and lowest) switch case value</td>
964 <td>list of <code>size</code> relative branch targets. The targets are
965 relative to the address of the switch opcode, not of this table.
971 <p><b>Note:</b> The total number of code units for an instance of this
972 table is <code>(size * 2) + 4</code>.</p>
974 <h2><code>sparse-switch</code> Format</h2>
976 <table class="supplement">
987 <td>ushort = 0x0200</td>
988 <td>identifying pseudo-opcode</td>
993 <td>number of entries in the table</td>
998 <td>list of <code>size</code> key values, sorted low-to-high</td>
1003 <td>list of <code>size</code> relative branch targets, each corresponding
1004 to the key value at the same index. The targets are
1005 relative to the address of the switch opcode, not of this table.
1011 <p><b>Note:</b> The total number of code units for an instance of this
1012 table is <code>(size * 4) + 2</code>.</p>
1014 <h2><code>fill-array-data</code> Format</h2>
1016 <table class="supplement">
1021 <th>Description</th>
1027 <td>ushort = 0x0300</td>
1028 <td>identifying pseudo-opcode</td>
1031 <td>element_width</td>
1033 <td>number of bytes in each element</td>
1038 <td>number of elements in the table</td>
1043 <td>data values</td>
1048 <p><b>Note:</b> The total number of code units for an instance of this
1049 table is <code>(size * element_width + 1) / 2 + 4</code>.</p>
1052 <h2>Mathematical Operation Details</h2>
1054 <p><b>Note:</b> Floating point operations must follow IEEE 754 rules, using
1055 round-to-nearest and gradual underflow, except where stated otherwise.</p>
1057 <table class="math">
1061 <th>C Semantics</th>
1071 <td>Unary twos-complement.</td>
1078 <td>Unary ones-complement.</td>
1085 <td>Unary twos-complement.</td>
1092 <td>Unary ones-complement.</td>
1099 <td>Floating point negation.</td>
1106 <td>Floating point negation.</td>
1109 <td>int-to-long</td>
1111 int64 result = (int64) a;
1113 <td>Sign extension of <code>int32</code> into <code>int64</code>.</td>
1116 <td>int-to-float</td>
1118 float result = (float) a;
1120 <td>Conversion of <code>int32</code> to <code>float</code>, using
1121 round-to-nearest. This loses precision for some values.
1125 <td>int-to-double</td>
1127 double result = (double) a;
1129 <td>Conversion of <code>int32</code> to <code>double</code>.</td>
1132 <td>long-to-int</td>
1134 int32 result = (int32) a;
1136 <td>Truncation of <code>int64</code> into <code>int32</code>.</td>
1139 <td>long-to-float</td>
1141 float result = (float) a;
1143 <td>Conversion of <code>int64</code> to <code>float</code>, using
1144 round-to-nearest. This loses precision for some values.
1148 <td>long-to-double</td>
1150 double result = (double) a;
1152 <td>Conversion of <code>int64</code> to <code>double</code>, using
1153 round-to-nearest. This loses precision for some values.
1157 <td>float-to-int</td>
1159 int32 result = (int32) a;
1161 <td>Conversion of <code>float</code> to <code>int32</code>, using
1162 round-toward-zero. <code>NaN</code> and <code>-0.0</code> (negative zero)
1163 convert to the integer <code>0</code>. Infinities and values with
1164 too large a magnitude to be represented get converted to either
1165 <code>0x7fffffff</code> or <code>-0x80000000</code> depending on sign.
1169 <td>float-to-long</td>
1171 int64 result = (int64) a;
1173 <td>Conversion of <code>float</code> to <code>int64</code>, using
1174 round-toward-zero. The same special case rules as for
1175 <code>float-to-int</code> apply here, except that out-of-range values
1176 get converted to either <code>0x7fffffffffffffff</code> or
1177 <code>-0x8000000000000000</code> depending on sign.
1181 <td>float-to-double</td>
1183 double result = (double) a;
1185 <td>Conversion of <code>float</code> to <code>double</code>, preserving
1190 <td>double-to-int</td>
1192 int32 result = (int32) a;
1194 <td>Conversion of <code>double</code> to <code>int32</code>, using
1195 round-toward-zero. The same special case rules as for
1196 <code>float-to-int</code> apply here.
1200 <td>double-to-long</td>
1202 int64 result = (int64) a;
1204 <td>Conversion of <code>double</code> to <code>int64</code>, using
1205 round-toward-zero. The same special case rules as for
1206 <code>float-to-long</code> apply here.
1210 <td>double-to-float</td>
1212 float result = (float) a;
1214 <td>Conversion of <code>double</code> to <code>float</code>, using
1215 round-to-nearest. This loses precision for some values.
1219 <td>int-to-byte</td>
1221 int32 result = (a << 24) >> 24;
1223 <td>Truncation of <code>int32</code> to <code>int8</code>, sign
1224 extending the result.
1228 <td>int-to-char</td>
1230 int32 result = a & 0xffff;
1232 <td>Truncation of <code>int32</code> to <code>uint16</code>, without
1237 <td>int-to-short</td>
1239 int32 result = (a << 16) >> 16;
1241 <td>Truncation of <code>int32</code> to <code>int16</code>, sign
1242 extending the result.
1247 <td>int32 a, b;<br/>
1248 int32 result = a + b;
1250 <td>Twos-complement addition.</td>
1254 <td>int32 a, b;<br/>
1255 int32 result = a - b;
1257 <td>Twos-complement subtraction.</td>
1261 <td>int32 a, b;<br/>
1262 int32 result = b - a;
1264 <td>Twos-complement reverse subtraction.</td>
1268 <td>int32 a, b;<br/>
1269 int32 result = a * b;
1271 <td>Twos-complement multiplication.</td>
1275 <td>int32 a, b;<br/>
1276 int32 result = a / b;
1278 <td>Twos-complement division, rounded towards zero (that is, truncated to
1279 integer). This throws <code>ArithmeticException</code> if
1280 <code>b == 0</code>.
1285 <td>int32 a, b;<br/>
1286 int32 result = a % b;
1288 <td>Twos-complement remainder after division. The sign of the result
1289 is the same as that of <code>a</code>, and it is more precisely
1290 defined as <code>result == a - (a / b) * b</code>. This throws
1291 <code>ArithmeticException</code> if <code>b == 0</code>.
1296 <td>int32 a, b;<br/>
1297 int32 result = a & b;
1299 <td>Bitwise AND.</td>
1303 <td>int32 a, b;<br/>
1304 int32 result = a | b;
1306 <td>Bitwise OR.</td>
1310 <td>int32 a, b;<br/>
1311 int32 result = a ^ b;
1313 <td>Bitwise XOR.</td>
1317 <td>int32 a, b;<br/>
1318 int32 result = a << (b & 0x1f);
1320 <td>Bitwise shift left (with masked argument).</td>
1324 <td>int32 a, b;<br/>
1325 int32 result = a >> (b & 0x1f);
1327 <td>Bitwise signed shift right (with masked argument).</td>
1331 <td>uint32 a, b;<br/>
1332 int32 result = a >> (b & 0x1f);
1334 <td>Bitwise unsigned shift right (with masked argument).</td>
1338 <td>int64 a, b;<br/>
1339 int64 result = a + b;
1341 <td>Twos-complement addition.</td>
1345 <td>int64 a, b;<br/>
1346 int64 result = a - b;
1348 <td>Twos-complement subtraction.</td>
1352 <td>int64 a, b;<br/>
1353 int64 result = a * b;
1355 <td>Twos-complement multiplication.</td>
1359 <td>int64 a, b;<br/>
1360 int64 result = a / b;
1362 <td>Twos-complement division, rounded towards zero (that is, truncated to
1363 integer). This throws <code>ArithmeticException</code> if
1364 <code>b == 0</code>.
1369 <td>int64 a, b;<br/>
1370 int64 result = a % b;
1372 <td>Twos-complement remainder after division. The sign of the result
1373 is the same as that of <code>a</code>, and it is more precisely
1374 defined as <code>result == a - (a / b) * b</code>. This throws
1375 <code>ArithmeticException</code> if <code>b == 0</code>.
1380 <td>int64 a, b;<br/>
1381 int64 result = a & b;
1383 <td>Bitwise AND.</td>
1387 <td>int64 a, b;<br/>
1388 int64 result = a | b;
1390 <td>Bitwise OR.</td>
1394 <td>int64 a, b;<br/>
1395 int64 result = a ^ b;
1397 <td>Bitwise XOR.</td>
1401 <td>int64 a, b;<br/>
1402 int64 result = a << (b & 0x3f);
1404 <td>Bitwise shift left (with masked argument).</td>
1408 <td>int64 a, b;<br/>
1409 int64 result = a >> (b & 0x3f);
1411 <td>Bitwise signed shift right (with masked argument).</td>
1415 <td>uint64 a, b;<br/>
1416 int64 result = a >> (b & 0x3f);
1418 <td>Bitwise unsigned shift right (with masked argument).</td>
1422 <td>float a, b;<br/>
1423 float result = a + b;
1425 <td>Floating point addition.</td>
1429 <td>float a, b;<br/>
1430 float result = a - b;
1432 <td>Floating point subtraction.</td>
1436 <td>float a, b;<br/>
1437 float result = a * b;
1439 <td>Floating point multiplication.</td>
1443 <td>float a, b;<br/>
1444 float result = a / b;
1446 <td>Floating point division.</td>
1450 <td>float a, b;<br/>
1451 float result = a % b;
1453 <td>Floating point remainder after division. This function is different
1454 than IEEE 754 remainder and is defined as
1455 <code>result == a - roundTowardZero(a / b) * b</code>.
1460 <td>double a, b;<br/>
1461 double result = a + b;
1463 <td>Floating point addition.</td>
1467 <td>double a, b;<br/>
1468 double result = a - b;
1470 <td>Floating point subtraction.</td>
1474 <td>double a, b;<br/>
1475 double result = a * b;
1477 <td>Floating point multiplication.</td>
1481 <td>double a, b;<br/>
1482 double result = a / b;
1484 <td>Floating point division.</td>
1488 <td>double a, b;<br/>
1489 double result = a % b;
1491 <td>Floating point remainder after division. This function is different
1492 than IEEE 754 remainder and is defined as
1493 <code>result == a - roundTowardZero(a / b) * b</code>.