# instance-of

## Purpose

Store in the given destination register 1 if the indicated reference is an instance of the given type, or 0 if not. The type must be a reference type (not a primitive type).

## Details

Op & Format | Mnemonic / Syntax | Arguments
--- | --- | ---
20 22c | instance-of vA, vB, type@CCCC | `A:` destination register (4 bits) `B:` reference-bearing register (4 bits) `C:` type index (16 bits)

## Constraints

- Both A and B must be a valid register indices for the current stack frame.
- Register vB must contain a reference value.
- C must be a valid index into the type constant pool.
- Type constant pool entry C must contain a valid type descriptor for a reference type.

## Behavior

- An attempt is made to get a reference to the class K the name of which is contained in type pool entry C.
- If K has not been loaded and resolved before, it is being loaded and resolved. All exceptions that are possible during class loading can occur at this point.
- The run-time type of the object reference vB is compared against K. The register vA reflects the result:
  - vA' = 1 if (and only if) vB is not null and vB is assignment compatible with K according to the usual rules of the Java programming language.
  - vA' = 0 otherwise
- If v(A-1) is the lower half of a register pair, v(A-1)' becomes undefined.
- If v(A+1) is the upper half of a register pair, v(A+1)' becomes undefined.

## Exceptions

None.