# const

## Purpose

Move the given literal value (sign-extended to 32 bits, if necessary) into the specified register.

## Details

Op & Format | Mnemonic / Syntax | Arguments
--- | --- | ---
12 11n | const/4 vA, #+B | `A:` destination register (4 bits) `B:` signed int (4 bits)
13 21s | const/16 vAA, #+BBBB | `A:` destination register (8 bits) `B:` signed int (16 bits)
14 31i | const vAA, #+BBBBBBBB | `A:` destination register (8 bits) `B:` arbitrary 32-bit constant
15 21h | const/high16 vAA, #+BBBB0000 | `A:` destination register (8 bits) `B:` signed int (16 bits)

## Constraints

- A must be a valid register index in the current stackframe.

## Behavior

- First, an adjusted value B' is determined as follows:
  - If we are executing the /high16 variant, then B is left-shifted by 16 bits, that is, B'=B << 0x10
  - Otherwise, if B is a 4 bit or 16 bit constant, it is sign-extended to 32 bits, that is, B'=sign-extended(B).
  - Otherwise, B'=B.
- Then, the adjusted value B' is moved into the register A, that is, vA'=B'
- 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.