Assembly Syntax

Operands

The following operand syntax types are used in instructions

ShortNameDescription
GPRGPR operandA General Purpose Register
SGPRShifted GPR operandA General Purpose Register Left-shifted by a constant
IORI/O Register operandAn I/O Transfer Register (Map 3)
ANYREGAny RegisterAny Register operand
UIMM16Immediate (unsigned 16-bit)16-bit Immediate operand
SIMM16Immediate (signed 16-bit)16-bit Immediate operand
PCREL16PC Relative Address (16-bit)16-bit offset from IP in bytes
OFF20Jump Offset (signed 20-bit)20-bit jump offset in words
UIMM32Immediate (unsigned 32-bit)32-bit immediate operand
SIMM32Immediate (signed 32-bit)32-bit immediate operand
BITWBit WidthWidth of a value in bits
BYTESZByte SizeSize of a value in bytes
ABSIMM2Immediate (unsigned 2-bit)2-bit absolute (non-relocated) immediate
ABSIMM5Immediate (unsigned 5-bit)5-bit absolute (non-relocated) immediate
ABSIMM6Immediate (unsigned 6-bit)6-bit absolute (non-relocated) immediate
ABSIMM8Immediate (unsigned 8-bit)8-bit absolute (non-relocated) immediate
CCCondition Code NameA condition Code

GPR operands

A GPR operand is written as r followed by the index number of the register.

Shifted GPR

A Shifted GPR operand is written as GPR << ABSIMM5

I/O Register Operand

An I/O Register Operand is written as io followed by the index number of the register.

Any Register

A Register in any map is either a GPR operand, and I/O Register operand, a system configuration register, a system information register, or a coprocessor register.

A system configuration register is written as either sys followed by the index number of the register or the alias name specified in the ISA (for example, the System Control Register may be written as sys0 or sysctl).

A system information register is written as info followed by the index number of the register.

A coprocessor register is written as co followed by the coprocessor number between 0 and 3, followed by r, followed by the register number. If the Assembler is aware of the particular coprocessor expected in a given coprocessor slot, it may use the alias name provided by the Coprocessor's Assembly Supplement. For example, if the Assembler is aware of the presence of a FPU (according to <float-coproc.md>) in slot 0, it may alias f0 as co0r0.

Immediates

Immediate operands take an integer or a symbol. n-bit Unsigned Immediates require an unsigned quantity in [0,2^n). Signed Immediates require a signed quantity in [-2^(n-1), 2^(n-1)).

Other than Absolute Immediates (like ABSIMM6), immediate operands can have symbols. Unless specified with the @pcrel modifier, Immediate operands always treat symbols as absolute address in relocations. The relocation requires that the address fits in the specified size of immediate (a link error occurs if it does not). using the special modifiers HI and LO allows you to instead specify the lower or upper 16-bits of the symbol.

Unless modified, immediate relocations uses (given the appropriate n):

  • R_MICRON_<n>
  • R_MICRON_LO16 (LO <sym>)
  • R_MICRON_HI16 (HI <sym>)

With the @pcrel modifier (or for PCREL16, see below), the relocation uses (given the appropriate n):

  • R_MICRON_PC16
  • R_MICRON_LOPC16 (LO <sym>@pcrel)
  • R_MICRON_HIPC16 (HI <sym>@pcrel)

Offsets

The PCREL16 and OFF20 values are special cases of immediates. PCREL16 is identical to a SIMM16 relocation, except that it defaults to resolving the specified symbol using a pc-relative relocation.

OFF20 is a 20-bit immediate that resolves a 22-bit pc-relative relocation or a 22-bit signed integer offset, and discards the lower two bits to encode the instruction. It has two constraints, in addition to the constraints that would apply to a 22-bit signed immediate:

  • Absolute Expressions must be divisible by 4, and
  • Relocation Expressions must produce a 4-byte aligned quantity. The Assembler may error if a misalignment is reliably detected (for example, a 3-byte offset from a symbol known to be 4-byte aligned).

OFF20 uses R_MICRON_JMPOFF relocation.

Sizes/Widths

A size or width expression is an absolute immediate that encodes a size (in bytes) or a width (in bits).

A BITW operand is a 5-bit unsigned absolute immediate that can take on any value between 1 and 32. 32 is encoded as 0. As a special case, the following synthetic constants are defined for BITW operands with the following values:

  • byte: 8
  • half: 16
  • word: 32.

A BYTESZ operand is a 2-bit immediate with a special encoding of lg(sz) where sz is the real size in bytes. The value must be a power of 2 less than 8. The same synthetic constants are defined above to be 1, 2, and 4 respectively.

Condition Code

Condition Codes appear only in mnemonics, and use the following 1 or 2 character short forms:

Short FormCondition NameNumberCanonical
NVNever0Yes
CCarry1Yes
BBelow1No
ZZero2Yes
EQEqual2No
VOverflow3Yes
OOverflow3No
CECarry/Equal4Yes
BEBelow or Equal4No
LTLess5Yes
LELess or Equal6Yes
NNegative7Yes
SSigned7No
PPositive8Yes
NSNot Signed8No
GTGreater Than9Yes
NLENot Less or Equal9No
GEGreater or Equal10Yes
NLTNot Less10No
AAbove11Yes
NBENot Below or Equal11No
NCENot Carry or Equal11No
NVNot Overflow12Yes
NONot Overflow12No
NZNot Zero13Yes
NENot Equal13No
NCNot Carry14Yes
NBNot Below14No
AEAbove or Equal14No
ALAlways15Yes

Instruction Syntax

The following charts describes how assemblers should interpret and assemble given instruction syntax forms and mnemonics.

Each Chart has the following information:

  • Mnemonic: The name of the instruction, which should be interpreted case-insentively. The special variables <c> and <x> may be written here. c is as if defined CC <c> and x is as if defined ABSIMM2 <x>.
  • Operands: A list of operands written as the Short ID followed by a variable in <> (e.g. GPR <d>)
  • Opcode: The Opcode of the instruction. This may reference the special variable x if defined in the Mnemonic.
  • Special Payload Encoding: A list of variable assignments of the form <var>=<val> where var is an encoding variable defined for the opcode in the ISA Spec, and val is either an integer expression or a variable. Implicitly the name of each encoding variable that is defined as a syntax variable in the Mnemonic or the Operands list is assigned to the value of that syntax variable. The special encoding variable P refers to the entire 24-bit payload (where its contents are undefined/ignored)
  • Canonical: Describes whether or not the instruction specification is canonical Canonical Specifications are the primary (or only) way to describe a particular encoding (without a .instr directive). Non-canonical encodings may describe a more efficient way to write or read a particular encoding, or may be useful in niche circumstances. Disassemblers and machine-code generators (such as assembly printing from a compiler) should prefer the canonical specification if it has no context otherwise.

UND

MnemonicOperandsOpcodeSpecial Payload EncodingCanonical
UND-0x00P=0Yes

PAUSE

MnemonicOperandsOpcodeSpecial Payload EncodingCanonical
PAUSEABSIMM6 <k>0x01N/AYes
NOP-0x01k=0No

MOV

MnemonicOperandsOpcodeSpecial Payload EncodingCanonical
MOV<c>GPR <d>, GPR <s>0x02m=0, r=0, l=0Yes
MOV<c>GPR <d>, ANYREG <s>0x02m=MAP(s), r=0, l=0Yes
MOV<c>ANYREG <d>, GPR <s>0x02m=MAP(d), r=1, l=0Yes
MOVGPR <d>, GPR <s>0x02m=0, r=0, l=0, c=15No
MOVGPR <d>, ANYREG <s>0x02m=MAP(s), r=0, l=0, c=15No
MOVANYREG <d>, GPR <s>0x02m=MAP(d), r=1, l=0, c=15No
MOVL<c>GPR <d>, GPR <s>0x02m=0, r=0, l=1Yes
MOVL<c>GPR <d>, ANYREG <s>0x02m=MAP(s), r=0, l=1Yes
MOVL<c>ANYREG <d>, GPR <s>0x02m=MAP(d), r=1, l=1Yes

LD/ST

MnemonicOperandsOpcodeSpecial Payload EncodingCanonical
LDGPR <d>, GPR <s>, BYTESZ <w>0x03p=0Yes
STGPR <d>, GPR <s>, BYTESZ <w>0x04p=0Yes
LDGPR <d>, GPR <s>0x03p=0,w=4No
STGPR <d>, GPR <s>0x04p=0,w=4No
PUSHGPR <d>, GPR <s>, BYTESZ <w>0x04p=1Yes
POPGPR <d>, GPR <s>, BYTESZ <w>0x03p=1Yes
PUSHGPR <d>, GPR <s>0x04p=1,w=4No
POPGPR <d>, GPR <s>0x03p=1,w=4No
PUSHGPR <s>0x04p=1,w=4,d=30No
POPGPR <d>0x03p=1,w=4,d=30No

ADDI

MnemonicOperandsOpcodeSpecial Payload EncodingCanonical
ADDIGPR <d>, SIMM16 <s>0x08