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 are limited to only addressing
54 registers. When reasonably possible, instructions allow references to
55 up to the first 256 registers. In cases where an instruction variant isn't
56 available to address a desired register, it is expected that the register
57 contents get moved from the original register to a low register (before the
58 operation) and/or moved from a low result register to a high register
59 (after the operation).
61 <li>There are several "pseudo-instructions" that are used to hold
62 variable-length data referred to by regular instructions (for example,
63 <code>fill-array-data</code>). Such instructions must never be
64 encountered during the normal flow of execution. In addition, the
65 instructions must be located on even-numbered bytecode offsets (that is,
66 4-byte aligned). In order to meet this requirement, dex generation tools
67 should emit an extra <code>nop</code> instruction as a spacer if such an
68 instruction would otherwise be unaligned. Finally, though not required,
69 it is expected that most tools will choose to emit these instructions at
70 the ends of methods, since otherwise it would likely be the case that
71 additional instructions would be needed to branch around them.
73 <li>When installed on a running system, some instructions may be altered,
74 changing their format, as an install-time static linking optimization.
75 This is to allow for faster execution once linkage is known.
77 <a href="instruction-formats.html">instruction formats document</a>
78 for the suggested variants. The word "suggested" is used advisedly;
79 it is not mandatory to implement these.
81 <li>Human-syntax and mnemonics:
83 <li>Dest-then-source ordering for arguments.</li>
84 <li>Some opcodes have a disambiguating suffix with respect to the type(s)
85 they operate on: Type-general 64-bit opcodes
86 are suffixed with <code>-wide</code>.
87 Type-specific opcodes are suffixed with their type (or a
88 straightforward abbreviation), one of: <code>-boolean</code>
89 <code>-byte</code> <code>-char</code> <code>-short</code>
90 <code>-int</code> <code>-long</code> <code>-float</code>
91 <code>-double</code> <code>-object</code> <code>-string</code>
92 <code>-class</code> <code>-void</code>. Type-general 32-bit opcodes
95 <li>Some opcodes have a disambiguating suffix to distinguish
96 otherwise-identical operations that have different instruction layouts
97 or options. These suffixes are separated from the main names with a slash
98 ("<code>/</code>") and mainly exist at all to make there be a one-to-one
99 mapping with static constants in the code that generates and interprets
100 executables (that is, to reduce ambiguity for humans).
104 <li>See the <a href="instruction-formats.html">instruction formats
105 document</a> for more details about the various instruction formats
106 (listed under "Op & Format") as well as details about the opcode
111 <h2>Summary of Instruction Set</h2>
113 <table class="instruc">
116 <th>Op & Format</th>
117 <th>Mnemonic / Syntax</th>
127 <td>Waste cycles.</td>
132 <td><code>A:</code> destination register (4 bits)<br/>
133 <code>B:</code> source register (4 bits)</td>
134 <td>Move the contents of one non-object register to another.</td>
138 <td>move/from16 vAA, vBBBB</td>
139 <td><code>A:</code> destination register (8 bits)<br/>
140 <code>B:</code> source register (16 bits)</td>
141 <td>Move the contents of one non-object register to another.</td>
145 <td>move/16 vAAAA, vBBBB</td>
146 <td><code>A:</code> destination register (16 bits)<br/>
147 <code>B:</code> source register (16 bits)</td>
148 <td>Move the contents of one non-object register to another.</td>
152 <td>move-wide vA, vB</td>
153 <td><code>A:</code> destination register pair (4 bits)<br/>
154 <code>B:</code> source register pair (4 bits)</td>
155 <td>Move the contents of one register-pair to another.
157 It is legal to move from <code>v<i>N</i></code> to either
158 <code>v<i>N-1</i></code> or <code>v<i>N+1</i></code>, so implementations
159 must arrange for both halves of a register pair to be read before
160 anything is written.</p>
165 <td>move-wide/from16 vAA, vBBBB</td>
166 <td><code>A:</code> destination register pair (8 bits)<br/>
167 <code>B:</code> source register pair (16 bits)</td>
168 <td>Move the contents of one register-pair to another.
170 Implementation considerations are the same as <code>move-wide</code>,
176 <td>move-wide/16 vAAAA, vBBBB</td>
177 <td><code>A:</code> destination register pair (16 bits)<br/>
178 <code>B:</code> source register pair (16 bits)</td>
179 <td>Move the contents of one register-pair to another.
181 Implementation considerations are the same as <code>move-wide</code>,
187 <td>move-object vA, vB</td>
188 <td><code>A:</code> destination register (4 bits)<br/>
189 <code>B:</code> source register (4 bits)</td>
190 <td>Move the contents of one object-bearing register to another.</td>
194 <td>move-object/from16 vAA, vBBBB</td>
195 <td><code>A:</code> destination register (8 bits)<br/>
196 <code>B:</code> source register (16 bits)</td>
197 <td>Move the contents of one object-bearing register to another.</td>
201 <td>move-object/16 vAAAA, vBBBB</td>
202 <td><code>A:</code> destination register (16 bits)<br/>
203 <code>B:</code> source register (16 bits)</td>
204 <td>Move the contents of one object-bearing register to another.</td>
208 <td>move-result vAA</td>
209 <td><code>A:</code> destination register (8 bits)</td>
210 <td>Move the single-word non-object result of the most recent
211 <code>invoke-<i>kind</i></code> into the indicated register.
212 This must be done as the instruction immediately after an
213 <code>invoke-<i>kind</i></code> whose (single-word, non-object) result
214 is not to be ignored; anywhere else is invalid.</td>
218 <td>move-result-wide vAA</td>
219 <td><code>A:</code> destination register pair (8 bits)</td>
220 <td>Move the double-word result of the most recent
221 <code>invoke-<i>kind</i></code> into the indicated register pair.
222 This must be done as the instruction immediately after an
223 <code>invoke-<i>kind</i></code> whose (double-word) result
224 is not to be ignored; anywhere else is invalid.</td>
228 <td>move-result-object vAA</td>
229 <td><code>A:</code> destination register (8 bits)</td>
230 <td>Move the object result of the most recent <code>invoke-<i>kind</i></code>
231 into the indicated register. This must be done as the instruction
232 immediately after an <code>invoke-<i>kind</i></code> or
233 <code>filled-new-array</code>
234 whose (object) result is not to be ignored; anywhere else is invalid.</td>
238 <td>move-exception vAA</td>
239 <td><code>A:</code> destination register (8 bits)</td>
240 <td>Save a just-caught exception into the given register. This should
241 be the first instruction of any exception handler whose caught
242 exception is not to be ignored, and this instruction must <i>only</i>
243 ever occur as the first instruction of an exception handler; anywhere
244 else is invalid.</td>
250 <td>Return from a <code>void</code> method.</td>
255 <td><code>A:</code> return value register (8 bits)</td>
256 <td>Return from a single-width (32-bit) non-object value-returning
262 <td>return-wide vAA</td>
263 <td><code>A:</code> return value register-pair (8 bits)</td>
264 <td>Return from a double-width (64-bit) value-returning method.</td>
268 <td>return-object vAA</td>
269 <td><code>A:</code> return value register (8 bits)</td>
270 <td>Return from an object-returning method.</td>
274 <td>const/4 vA, #+B</td>
275 <td><code>A:</code> destination register (4 bits)<br/>
276 <code>B:</code> signed int (4 bits)</td>
277 <td>Move the given literal value (sign-extended to 32 bits) into
278 the specified register.</td>
282 <td>const/16 vAA, #+BBBB</td>
283 <td><code>A:</code> destination register (8 bits)<br/>
284 <code>B:</code> signed int (16 bits)</td>
285 <td>Move the given literal value (sign-extended to 32 bits) into
286 the specified register.</td>
290 <td>const vAA, #+BBBBBBBB</td>
291 <td><code>A:</code> destination register (8 bits)<br/>
292 <code>B:</code> arbitrary 32-bit constant</td>
293 <td>Move the given literal value into the specified register.</td>
297 <td>const/high16 vAA, #+BBBB0000</td>
298 <td><code>A:</code> destination register (8 bits)<br/>
299 <code>B:</code> signed int (16 bits)</td>
300 <td>Move the given literal value (right-zero-extended to 32 bits) into
301 the specified register.</td>
305 <td>const-wide/16 vAA, #+BBBB</td>
306 <td><code>A:</code> destination register (8 bits)<br/>
307 <code>B:</code> signed int (16 bits)</td>
308 <td>Move the given literal value (sign-extended to 64 bits) into
309 the specified register-pair.</td>
313 <td>const-wide/32 vAA, #+BBBBBBBB</td>
314 <td><code>A:</code> destination register (8 bits)<br/>
315 <code>B:</code> signed int (32 bits)</td>
316 <td>Move the given literal value (sign-extended to 64 bits) into
317 the specified register-pair.</td>
321 <td>const-wide vAA, #+BBBBBBBBBBBBBBBB</td>
322 <td><code>A:</code> destination register (8 bits)<br/>
323 <code>B:</code> arbitrary double-width (64-bit) constant</td>
324 <td>Move the given literal value into
325 the specified register-pair.</td>
329 <td>const-wide/high16 vAA, #+BBBB000000000000</td>
330 <td><code>A:</code> destination register (8 bits)<br/>
331 <code>B:</code> signed int (16 bits)</td>
332 <td>Move the given literal value (right-zero-extended to 64 bits) into
333 the specified register-pair.</td>
337 <td>const-string vAA, string@BBBB</td>
338 <td><code>A:</code> destination register (8 bits)<br/>
339 <code>B:</code> string index</td>
340 <td>Move a reference to the string specified by the given index into the
341 specified register.</td>
345 <td>const-string/jumbo vAA, string@BBBBBBBB</td>
346 <td><code>A:</code> destination register (8 bits)<br/>
347 <code>B:</code> string index</td>
348 <td>Move a reference to the string specified by the given index into the
349 specified register.</td>
353 <td>const-class vAA, type@BBBB</td>
354 <td><code>A:</code> destination register (8 bits)<br/>
355 <code>B:</code> type index</td>
356 <td>Move a reference to the class specified by the given index into the
357 specified register. In the case where the indicated type is primitive,
358 this will store a reference to the primitive type's degenerate
363 <td>monitor-enter vAA</td>
364 <td><code>A:</code> reference-bearing register (8 bits)</td>
365 <td>Acquire the monitor for the indicated object.</td>
369 <td>monitor-exit vAA</td>
370 <td><code>A:</code> reference-bearing register (8 bits)</td>
371 <td>Release the monitor for the indicated object.
373 If this instruction needs to throw an exception, it must do
374 so as if the pc has already advanced past the instruction.
375 It may be useful to think of this as the instruction successfully
376 executing (in a sense), and the exception getting thrown <i>after</i>
377 the instruction but <i>before</i> the next one gets a chance to
378 run. This definition makes it possible for a method to use
379 a monitor cleanup catch-all (e.g., <code>finally</code>) block as
380 the monitor cleanup for that block itself, as a way to handle the
381 arbitrary exceptions that might get thrown due to the historical
382 implementation of <code>Thread.stop()</code>, while still managing
383 to have proper monitor hygiene.</p>
388 <td>check-cast vAA, type@BBBB</td>
389 <td><code>A:</code> reference-bearing register (8 bits)<br/>
390 <code>B:</code> type index (16 bits)</td>
391 <td>Throw a <code>ClassCastException</code> if the reference in the
392 given register cannot be cast to the indicated type.
393 <p><b>Note:</b> Since <code>A</code> must always be a reference
394 (and not a primitive value), this will necessarily fail at runtime
395 (that is, it will throw an exception) if <code>B</code> refers to a
401 <td>instance-of vA, vB, type@CCCC</td>
402 <td><code>A:</code> destination register (4 bits)<br/>
403 <code>B:</code> reference-bearing register (4 bits)<br/>
404 <code>C:</code> type index (16 bits)</td>
405 <td>Store in the given destination register <code>1</code>
406 if the indicated reference is an instance of the given type,
407 or <code>0</code> if not.
408 <p><b>Note:</b> Since <code>B</code> must always be a reference
409 (and not a primitive value), this will always result
410 in <code>0</code> being stored if <code>C</code> refers to a primitive
415 <td>array-length vA, vB</td>
416 <td><code>A:</code> destination register (4 bits)<br/>
417 <code>B:</code> array reference-bearing register (4 bits)</td>
418 <td>Store in the given destination register the length of the indicated
419 array, in entries</td>
423 <td>new-instance vAA, type@BBBB</td>
424 <td><code>A:</code> destination register (8 bits)<br/>
425 <code>B:</code> type index</td>
426 <td>Construct a new instance of the indicated type, storing a
427 reference to it in the destination. The type must refer to a
428 non-array class.</td>
432 <td>new-array vA, vB, type@CCCC</td>
433 <td><code>A:</code> destination register (8 bits)<br/>
434 <code>B:</code> size register<br/>
435 <code>C:</code> type index</td>
436 <td>Construct a new array of the indicated type and size. The type
437 must be an array type.</td>
441 <td>filled-new-array {vD, vE, vF, vG, vA}, type@CCCC</td>
442 <td><code>B:</code> array size and argument word count (4 bits)<br/>
443 <code>C:</code> type index (16 bits)<br/>
444 <code>D..G, A:</code> argument registers (4 bits each)</td>
445 <td>Construct an array of the given type and size, filling it with the
446 supplied contents. The type must be an array type. The array's
447 contents must be single-word (that is,
448 no arrays of <code>long</code> or <code>double</code>, but reference
449 types are acceptable). The constructed
450 instance is stored as a "result" in the same way that the method invocation
451 instructions store their results, so the constructed instance must
452 be moved to a register with an immediately subsequent
453 <code>move-result-object</code> instruction (if it is to be used).</td>
457 <td>filled-new-array/range {vCCCC .. vNNNN}, type@BBBB</td>
458 <td><code>A:</code> array size and argument word count (8 bits)<br/>
459 <code>B:</code> type index (16 bits)<br/>
460 <code>C:</code> first argument register (16 bits)<br/>
461 <code>N = A + C - 1</code></td>
462 <td>Construct an array of the given type and size, filling it with
463 the supplied contents. Clarifications and restrictions are the same
464 as <code>filled-new-array</code>, described above.</td>
468 <td>fill-array-data vAA, +BBBBBBBB <i>(with supplemental data as specified
469 below in "<code>fill-array-data</code> Format")</i></td>
470 <td><code>A:</code> array reference (8 bits)<br/>
471 <code>B:</code> signed "branch" offset to table data pseudo-instruction
474 <td>Fill the given array with the indicated data. The reference must be
475 to an array of primitives, and the data table must match it in type and
476 must contain no more elements than will fit in the array. That is,
477 the array may be larger than the table, and if so, only the initial
478 elements of the array are set, leaving the remainder alone.
484 <td><code>A:</code> exception-bearing register (8 bits)<br/></td>
485 <td>Throw the indicated exception.</td>
490 <td><code>A:</code> signed branch offset (8 bits)</td>
491 <td>Unconditionally jump to the indicated instruction.
493 The branch offset must not be <code>0</code>. (A spin
494 loop may be legally constructed either with <code>goto/32</code> or
495 by including a <code>nop</code> as a target before the branch.)</p>
500 <td>goto/16 +AAAA</td>
501 <td><code>A:</code> signed branch offset (16 bits)<br/></td>
502 <td>Unconditionally jump to the indicated instruction.
504 The branch offset must not be <code>0</code>. (A spin
505 loop may be legally constructed either with <code>goto/32</code> or
506 by including a <code>nop</code> as a target before the branch.)</p>
511 <td>goto/32 +AAAAAAAA</td>
512 <td><code>A:</code> signed branch offset (32 bits)<br/></td>
513 <td>Unconditionally jump to the indicated instruction.</td>
517 <td>packed-switch vAA, +BBBBBBBB <i>(with supplemental data as
518 specified below in "<code>packed-switch</code> Format")</i></td>
519 <td><code>A:</code> register to test<br/>
520 <code>B:</code> signed "branch" offset to table data pseudo-instruction
523 <td>Jump to a new instruction based on the value in the
524 given register, using a table of offsets corresponding to each value
525 in a particular integral range, or fall through to the next
526 instruction if there is no match.
531 <td>sparse-switch vAA, +BBBBBBBB <i>(with supplemental data as
532 specified below in "<code>sparse-switch</code> Format")</i></td>
533 <td><code>A:</code> register to test<br/>
534 <code>B:</code> signed "branch" offset to table data pseudo-instruction
537 <td>Jump to a new instruction based on the value in the given
538 register, using an ordered table of value-offset pairs, or fall
539 through to the next instruction if there is no match.
544 <td>cmp<i>kind</i> vAA, vBB, vCC<br/>
545 2d: cmpl-float <i>(lt bias)</i><br/>
546 2e: cmpg-float <i>(gt bias)</i><br/>
547 2f: cmpl-double <i>(lt bias)</i><br/>
548 30: cmpg-double <i>(gt bias)</i><br/>
551 <td><code>A:</code> destination register (8 bits)<br/>
552 <code>B:</code> first source register or pair<br/>
553 <code>C:</code> second source register or pair</td>
554 <td>Perform the indicated floating point or <code>long</code> comparison,
555 storing <code>0</code> if the two arguments are equal, <code>1</code>
556 if the second argument is larger, or <code>-1</code> if the first
557 argument is larger. The "bias" listed for the floating point operations
558 indicates how <code>NaN</code> comparisons are treated: "Gt bias"
559 instructions return <code>1</code> for <code>NaN</code> comparisons,
560 and "lt bias" instructions return
562 <p>For example, to check to see if floating point
563 <code>a < b</code>, then it is advisable to use
564 <code>cmpg-float</code>; a result of <code>-1</code> indicates that
565 the test was true, and the other values indicate it was false either
566 due to a valid comparison or because one or the other values was
567 <code>NaN</code>.</p>
572 <td>if-<i>test</i> vA, vB, +CCCC<br/>
580 <td><code>A:</code> first register to test (4 bits)<br/>
581 <code>B:</code> second register to test (4 bits)<br/>
582 <code>C:</code> signed branch offset (16 bits)</td>
583 <td>Branch to the given destination if the given two registers' values
584 compare as specified.
586 The branch offset must not be <code>0</code>. (A spin
587 loop may be legally constructed either by branching around a
588 backward <code>goto</code> or by including a <code>nop</code> as
589 a target before the branch.)</p>
594 <td>if-<i>test</i>z vAA, +BBBB<br/>
602 <td><code>A:</code> register to test (8 bits)<br/>
603 <code>B:</code> signed branch offset (16 bits)</td>
604 <td>Branch to the given destination if the given register's value compares
607 The branch offset must not be <code>0</code>. (A spin
608 loop may be legally constructed either by branching around a
609 backward <code>goto</code> or by including a <code>nop</code> as
610 a target before the branch.)</p>
615 <td><i>(unused)</i></td>
617 <td><i>(unused)</i></td>
621 <td><i>arrayop</i> vAA, vBB, vCC<br/>
625 47: aget-boolean<br/>
632 4e: aput-boolean<br/>
637 <td><code>A:</code> value register or pair; may be source or dest
639 <code>B:</code> array register (8 bits)<br/>
640 <code>C:</code> index register (8 bits)</td>
641 <td>Perform the identified array operation at the identified index of
642 the given array, loading or storing into the value register.</td>
646 <td>i<i>instanceop</i> vA, vB, field@CCCC<br/>
650 55: iget-boolean<br/>
657 5c: iput-boolean<br/>
662 <td><code>A:</code> value register or pair; may be source or dest
664 <code>B:</code> object register (4 bits)<br/>
665 <code>C:</code> instance field reference index (16 bits)</td>
666 <td>Perform the identified object instance field operation with
667 the identified field, loading or storing into the value register.
668 <p><b>Note:</b> These opcodes are reasonable candidates for static linking,
669 altering the field argument to be a more direct offset.</p>
674 <td>s<i>staticop</i> vAA, field@BBBB<br/>
678 63: sget-boolean<br/>
685 6a: sput-boolean<br/>
690 <td><code>A:</code> value register or pair; may be source or dest
692 <code>B:</code> static field reference index (16 bits)</td>
693 <td>Perform the identified object static field operation with the identified
694 static field, loading or storing into the value register.
695 <p><b>Note:</b> These opcodes are reasonable candidates for static linking,
696 altering the field argument to be a more direct offset.</p>
701 <td>invoke-<i>kind</i> {vD, vE, vF, vG, vA}, meth@CCCC<br/>
702 6e: invoke-virtual<br/>
703 6f: invoke-super<br/>
704 70: invoke-direct<br/>
705 71: invoke-static<br/>
708 <td><code>B:</code> argument word count (4 bits)<br/>
709 <code>C:</code> method index (16 bits)<br/>
710 <code>D..G, A:</code> argument registers (4 bits each)</td>
711 <td>Call the indicated method. The result (if any) may be stored
712 with an appropriate <code>move-result*</code> variant as the immediately
713 subsequent instruction.
714 <p><code>invoke-virtual</code> is used to invoke a normal virtual
715 method (a method that is not <code>private</code>, <code>static</code>,
716 or <code>final</code>, and is also not a constructor).</p>
717 <p><code>invoke-super</code> is used to invoke the closest superclass's
718 virtual method (as opposed to the one with the same <code>method_id</code>
719 in the calling class). The same method restrictions hold as for
720 <code>invoke-virtual</code>.</p>
721 <p><code>invoke-direct</code> is used to invoke a non-<code>static</code>
722 direct method (that is, an instance method that is by its nature
723 non-overridable, namely either a <code>private</code> instance method
724 or a constructor).</p>
725 <p><code>invoke-static</code> is used to invoke a <code>static</code>
726 method (which is always considered a direct method).</p>
727 <p><code>invoke-interface</code> is used to invoke an
728 <code>interface</code> method, that is, on an object whose concrete
729 class isn't known, using a <code>method_id</code> that refers to
730 an <code>interface</code>.</p>
731 <p><b>Note:</b> These opcodes are reasonable candidates for static linking,
732 altering the method argument to be a more direct offset
733 (or pair thereof).</p>
738 <td><i>(unused)</i></td>
740 <td><i>(unused)</i></td>
744 <td>invoke-<i>kind</i>/range {vCCCC .. vNNNN}, meth@BBBB<br/>
745 74: invoke-virtual/range<br/>
746 75: invoke-super/range<br/>
747 76: invoke-direct/range<br/>
748 77: invoke-static/range<br/>
749 78: invoke-interface/range
751 <td><code>A:</code> argument word count (8 bits)<br/>
752 <code>B:</code> method index (16 bits)<br/>
753 <code>C:</code> first argument register (16 bits)<br/>
754 <code>N = A + C - 1</code></td>
755 <td>Call the indicated method. See first <code>invoke-<i>kind</i></code>
756 description above for details, caveats, and suggestions.
761 <td><i>(unused)</i></td>
763 <td><i>(unused)</i></td>
767 <td><i>unop</i> vA, vB<br/>
775 82: int-to-float<br/>
776 83: int-to-double<br/>
778 85: long-to-float<br/>
779 86: long-to-double<br/>
780 87: float-to-int<br/>
781 88: float-to-long<br/>
782 89: float-to-double<br/>
783 8a: double-to-int<br/>
784 8b: double-to-long<br/>
785 8c: double-to-float<br/>
790 <td><code>A:</code> destination register or pair (4 bits)<br/>
791 <code>B:</code> source register or pair (4 bits)</td>
792 <td>Perform the identified unary operation on the source register,
793 storing the result in the destination register.</td>
798 <td><i>binop</i> vAA, vBB, vCC<br/>
832 <td><code>A:</code> destination register or pair (8 bits)<br/>
833 <code>B:</code> first source register or pair (8 bits)<br/>
834 <code>C:</code> second source register or pair (8 bits)</td>
835 <td>Perform the identified binary operation on the two source registers,
836 storing the result in the first source register.</td>
840 <td><i>binop</i>/2addr vA, vB<br/>
841 b0: add-int/2addr<br/>
842 b1: sub-int/2addr<br/>
843 b2: mul-int/2addr<br/>
844 b3: div-int/2addr<br/>
845 b4: rem-int/2addr<br/>
846 b5: and-int/2addr<br/>
847 b6: or-int/2addr<br/>
848 b7: xor-int/2addr<br/>
849 b8: shl-int/2addr<br/>
850 b9: shr-int/2addr<br/>
851 ba: ushr-int/2addr<br/>
852 bb: add-long/2addr<br/>
853 bc: sub-long/2addr<br/>
854 bd: mul-long/2addr<br/>
855 be: div-long/2addr<br/>
856 bf: rem-long/2addr<br/>
857 c0: and-long/2addr<br/>
858 c1: or-long/2addr<br/>
859 c2: xor-long/2addr<br/>
860 c3: shl-long/2addr<br/>
861 c4: shr-long/2addr<br/>
862 c5: ushr-long/2addr<br/>
863 c6: add-float/2addr<br/>
864 c7: sub-float/2addr<br/>
865 c8: mul-float/2addr<br/>
866 c9: div-float/2addr<br/>
867 ca: rem-float/2addr<br/>
868 cb: add-double/2addr<br/>
869 cc: sub-double/2addr<br/>
870 cd: mul-double/2addr<br/>
871 ce: div-double/2addr<br/>
874 <td><code>A:</code> destination and first source register or pair
876 <code>B:</code> second source register or pair (4 bits)</td>
877 <td>Perform the identified binary operation on the two source registers,
878 storing the result in the first source register.</td>
882 <td><i>binop</i>/lit16 vA, vB, #+CCCC<br/>
883 d0: add-int/lit16<br/>
884 d1: rsub-int (reverse subtract)<br/>
885 d2: mul-int/lit16<br/>
886 d3: div-int/lit16<br/>
887 d4: rem-int/lit16<br/>
888 d5: and-int/lit16<br/>
889 d6: or-int/lit16<br/>
892 <td><code>A:</code> destination register (4 bits)<br/>
893 <code>B:</code> source register (4 bits)<br/>
894 <code>C:</code> signed int constant (16 bits)</td>
895 <td>Perform the indicated binary op on the indicated register (first
896 argument) and literal value (second argument), storing the result in
897 the destination register.
899 <code>rsub-int</code> does not have a suffix since this version is the
900 main opcode of its family. Also, see below for details on its semantics.
906 <td><i>binop</i>/lit8 vAA, vBB, #+CC<br/>
907 d8: add-int/lit8<br/>
908 d9: rsub-int/lit8<br/>
909 da: mul-int/lit8<br/>
910 db: div-int/lit8<br/>
911 dc: rem-int/lit8<br/>
912 dd: and-int/lit8<br/>
914 df: xor-int/lit8<br/>
915 e0: shl-int/lit8<br/>
916 e1: shr-int/lit8<br/>
919 <td><code>A:</code> destination register (8 bits)<br/>
920 <code>B:</code> source register (8 bits)<br/>
921 <code>C:</code> signed int constant (8 bits)</td>
922 <td>Perform the indicated binary op on the indicated register (first
923 argument) and literal value (second argument), storing the result
924 in the destination register.
925 <p><b>Note:</b> See below for details on the semantics of
926 <code>rsub-int</code>.</p>
931 <td><i>(unused)</i></td>
933 <td><i>(unused)</i></td>
938 <h2><code>packed-switch</code> Format</h2>
940 <table class="supplement">
951 <td>ushort = 0x0100</td>
952 <td>identifying pseudo-opcode</td>
957 <td>number of entries in the table</td>
962 <td>first (and lowest) switch case value</td>
967 <td>list of <code>size</code> relative branch targets. The targets are
968 relative to the address of the switch opcode, not of this table.
974 <p><b>Note:</b> The total number of code units for an instance of this
975 table is <code>(size * 2) + 4</code>.</p>
977 <h2><code>sparse-switch</code> Format</h2>
979 <table class="supplement">
990 <td>ushort = 0x0200</td>
991 <td>identifying pseudo-opcode</td>
996 <td>number of entries in the table</td>
1001 <td>list of <code>size</code> key values, sorted low-to-high</td>
1006 <td>list of <code>size</code> relative branch targets, each corresponding
1007 to the key value at the same index. The targets are
1008 relative to the address of the switch opcode, not of this table.
1014 <p><b>Note:</b> The total number of code units for an instance of this
1015 table is <code>(size * 4) + 2</code>.</p>
1017 <h2><code>fill-array-data</code> Format</h2>
1019 <table class="supplement">
1024 <th>Description</th>
1030 <td>ushort = 0x0300</td>
1031 <td>identifying pseudo-opcode</td>
1034 <td>element_width</td>
1036 <td>number of bytes in each element</td>
1041 <td>number of elements in the table</td>
1046 <td>data values</td>
1051 <p><b>Note:</b> The total number of code units for an instance of this
1052 table is <code>(size * element_width + 1) / 2 + 4</code>.</p>
1055 <h2>Mathematical Operation Details</h2>
1057 <p><b>Note:</b> Floating point operations must follow IEEE 754 rules, using
1058 round-to-nearest and gradual underflow, except where stated otherwise.</p>
1060 <table class="math">
1064 <th>C Semantics</th>
1074 <td>Unary twos-complement.</td>
1081 <td>Unary ones-complement.</td>
1088 <td>Unary twos-complement.</td>
1095 <td>Unary ones-complement.</td>
1102 <td>Floating point negation.</td>
1109 <td>Floating point negation.</td>
1112 <td>int-to-long</td>
1114 int64 result = (int64) a;
1116 <td>Sign extension of <code>int32</code> into <code>int64</code>.</td>
1119 <td>int-to-float</td>
1121 float result = (float) a;
1123 <td>Conversion of <code>int32</code> to <code>float</code>, using
1124 round-to-nearest. This loses precision for some values.
1128 <td>int-to-double</td>
1130 double result = (double) a;
1132 <td>Conversion of <code>int32</code> to <code>double</code>.</td>
1135 <td>long-to-int</td>
1137 int32 result = (int32) a;
1139 <td>Truncation of <code>int64</code> into <code>int32</code>.</td>
1142 <td>long-to-float</td>
1144 float result = (float) a;
1146 <td>Conversion of <code>int64</code> to <code>float</code>, using
1147 round-to-nearest. This loses precision for some values.
1151 <td>long-to-double</td>
1153 double result = (double) a;
1155 <td>Conversion of <code>int64</code> to <code>double</code>, using
1156 round-to-nearest. This loses precision for some values.
1160 <td>float-to-int</td>
1162 int32 result = (int32) a;
1164 <td>Conversion of <code>float</code> to <code>int32</code>, using
1165 round-toward-zero. <code>NaN</code> and <code>-0.0</code> (negative zero)
1166 convert to the integer <code>0</code>. Infinities and values with
1167 too large a magnitude to be represented get converted to either
1168 <code>0x7fffffff</code> or <code>-0x80000000</code> depending on sign.
1172 <td>float-to-long</td>
1174 int64 result = (int64) a;
1176 <td>Conversion of <code>float</code> to <code>int64</code>, using
1177 round-toward-zero. The same special case rules as for
1178 <code>float-to-int</code> apply here, except that out-of-range values
1179 get converted to either <code>0x7fffffffffffffff</code> or
1180 <code>-0x8000000000000000</code> depending on sign.
1184 <td>float-to-double</td>
1186 double result = (double) a;
1188 <td>Conversion of <code>float</code> to <code>double</code>, preserving
1193 <td>double-to-int</td>
1195 int32 result = (int32) a;
1197 <td>Conversion of <code>double</code> to <code>int32</code>, using
1198 round-toward-zero. The same special case rules as for
1199 <code>float-to-int</code> apply here.
1203 <td>double-to-long</td>
1205 int64 result = (int64) a;
1207 <td>Conversion of <code>double</code> to <code>int64</code>, using
1208 round-toward-zero. The same special case rules as for
1209 <code>float-to-long</code> apply here.
1213 <td>double-to-float</td>
1215 float result = (float) a;
1217 <td>Conversion of <code>double</code> to <code>float</code>, using
1218 round-to-nearest. This loses precision for some values.
1222 <td>int-to-byte</td>
1224 int32 result = (a << 24) >> 24;
1226 <td>Truncation of <code>int32</code> to <code>int8</code>, sign
1227 extending the result.
1231 <td>int-to-char</td>
1233 int32 result = a & 0xffff;
1235 <td>Truncation of <code>int32</code> to <code>uint16</code>, without
1240 <td>int-to-short</td>
1242 int32 result = (a << 16) >> 16;
1244 <td>Truncation of <code>int32</code> to <code>int16</code>, sign
1245 extending the result.
1250 <td>int32 a, b;<br/>
1251 int32 result = a + b;
1253 <td>Twos-complement addition.</td>
1257 <td>int32 a, b;<br/>
1258 int32 result = a - b;
1260 <td>Twos-complement subtraction.</td>
1264 <td>int32 a, b;<br/>
1265 int32 result = b - a;
1267 <td>Twos-complement reverse subtraction.</td>
1271 <td>int32 a, b;<br/>
1272 int32 result = a * b;
1274 <td>Twos-complement multiplication.</td>
1278 <td>int32 a, b;<br/>
1279 int32 result = a / b;
1281 <td>Twos-complement division, rounded towards zero (that is, truncated to
1282 integer). This throws <code>ArithmeticException</code> if
1283 <code>b == 0</code>.
1288 <td>int32 a, b;<br/>
1289 int32 result = a % b;
1291 <td>Twos-complement remainder after division. The sign of the result
1292 is the same as that of <code>a</code>, and it is more precisely
1293 defined as <code>result == a - (a / b) * b</code>. This throws
1294 <code>ArithmeticException</code> if <code>b == 0</code>.
1299 <td>int32 a, b;<br/>
1300 int32 result = a & b;
1302 <td>Bitwise AND.</td>
1306 <td>int32 a, b;<br/>
1307 int32 result = a | b;
1309 <td>Bitwise OR.</td>
1313 <td>int32 a, b;<br/>
1314 int32 result = a ^ b;
1316 <td>Bitwise XOR.</td>
1320 <td>int32 a, b;<br/>
1321 int32 result = a << (b & 0x1f);
1323 <td>Bitwise shift left (with masked argument).</td>
1327 <td>int32 a, b;<br/>
1328 int32 result = a >> (b & 0x1f);
1330 <td>Bitwise signed shift right (with masked argument).</td>
1334 <td>uint32 a, b;<br/>
1335 int32 result = a >> (b & 0x1f);
1337 <td>Bitwise unsigned shift right (with masked argument).</td>
1341 <td>int64 a, b;<br/>
1342 int64 result = a + b;
1344 <td>Twos-complement addition.</td>
1348 <td>int64 a, b;<br/>
1349 int64 result = a - b;
1351 <td>Twos-complement subtraction.</td>
1355 <td>int64 a, b;<br/>
1356 int64 result = a * b;
1358 <td>Twos-complement multiplication.</td>
1362 <td>int64 a, b;<br/>
1363 int64 result = a / b;
1365 <td>Twos-complement division, rounded towards zero (that is, truncated to
1366 integer). This throws <code>ArithmeticException</code> if
1367 <code>b == 0</code>.
1372 <td>int64 a, b;<br/>
1373 int64 result = a % b;
1375 <td>Twos-complement remainder after division. The sign of the result
1376 is the same as that of <code>a</code>, and it is more precisely
1377 defined as <code>result == a - (a / b) * b</code>. This throws
1378 <code>ArithmeticException</code> if <code>b == 0</code>.
1383 <td>int64 a, b;<br/>
1384 int64 result = a & b;
1386 <td>Bitwise AND.</td>
1390 <td>int64 a, b;<br/>
1391 int64 result = a | b;
1393 <td>Bitwise OR.</td>
1397 <td>int64 a, b;<br/>
1398 int64 result = a ^ b;
1400 <td>Bitwise XOR.</td>
1404 <td>int64 a, b;<br/>
1405 int64 result = a << (b & 0x3f);
1407 <td>Bitwise shift left (with masked argument).</td>
1411 <td>int64 a, b;<br/>
1412 int64 result = a >> (b & 0x3f);
1414 <td>Bitwise signed shift right (with masked argument).</td>
1418 <td>uint64 a, b;<br/>
1419 int64 result = a >> (b & 0x3f);
1421 <td>Bitwise unsigned shift right (with masked argument).</td>
1425 <td>float a, b;<br/>
1426 float result = a + b;
1428 <td>Floating point addition.</td>
1432 <td>float a, b;<br/>
1433 float result = a - b;
1435 <td>Floating point subtraction.</td>
1439 <td>float a, b;<br/>
1440 float result = a * b;
1442 <td>Floating point multiplication.</td>
1446 <td>float a, b;<br/>
1447 float result = a / b;
1449 <td>Floating point division.</td>
1453 <td>float a, b;<br/>
1454 float result = a % b;
1456 <td>Floating point remainder after division. This function is different
1457 than IEEE 754 remainder and is defined as
1458 <code>result == a - roundTowardZero(a / b) * b</code>.
1463 <td>double a, b;<br/>
1464 double result = a + b;
1466 <td>Floating point addition.</td>
1470 <td>double a, b;<br/>
1471 double result = a - b;
1473 <td>Floating point subtraction.</td>
1477 <td>double a, b;<br/>
1478 double result = a * b;
1480 <td>Floating point multiplication.</td>
1484 <td>double a, b;<br/>
1485 double result = a / b;
1487 <td>Floating point division.</td>
1491 <td>double a, b;<br/>
1492 double result = a % b;
1494 <td>Floating point remainder after division. This function is different
1495 than IEEE 754 remainder and is defined as
1496 <code>result == a - roundTowardZero(a / b) * b</code>.