Assembly Syntax

Operands

The following operand syntax types are used in instructions

ShortNameDescription
GPRGPR operandA General Purpose Register
IGPRInvertible GPR OperandA potentially inverted gpr operand
SGPRShifted GPR operandA General Purpose Register Left-shifted by a constant
SIGPRShifted Invertible GPR operandA potentially inverted gpr operand Left-shifed 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
PCREL32PC Relative Address (32-bit)32-bit offset from IP in bytes
OFF17Jump 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
ABSIMM3Immediate (unsigned 3-bit)3-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
PRIOInterrupt PriorityAn interrupt priority level

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.

A shifted GPR operand produces two variables. The Operand Specification is written as <GPR> << <ABS>

Invertible GPRs

An invertible GPR is written as either GPR (non-inverted) or ~GPR (inverted). An IGPR produces two variables. The Operand Specification is written as <INV> <GPR>.

A Shifted invertible GPR operand is written the same as GPR << ABSIMM5, except that GPR may be inverted. An SIGPR produces three variables, written as <INV> <GPR> << <ABS>

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.

An interrupt register may be written as intrN or an alias name. Registers 1-3 may be written as intretN, Registers 4-7 are written intdN where N=r%4, Registers 8-11 are written intsN where N=r%4.

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 OFF15 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.

OFF15 is a 15-bit immediate that resolves a 17-bit pc-relative relocation or a 17-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).

OFF15 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.

Interrupt Priorities

An interrupt priority is a priority level for the IRET instruction. It may be written as an ABSIMM2 or one of the following keywords. A value of 0 assembles, but is an illegal instruction at runtime.

  • trap: 1
  • async: 2
  • irq: 3

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
OOverflow3Yes
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
NONot Overflow12Yes
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

Load/Add Immediates

MnemonicOperandsOpcodeSpecial Payload EncodingCanonical
LDIGPR <d>, SIMM16 <i>0x05x=1Yes
LDIUGPR <d>, UIMM16 <i>0x05x=0Yes
LRAGPR <d>, PCREL16 <i>0x06x=1Yes
LRAUGPR <d>, UPCREL16 <i>0x06x=0Yes
ADDIGPR <d>, SIMM16 <i>0x08x=1,f=1,h=0Yes
ADDIFGPR <d>, SIMM16 <i>0x08x=1,f=0,h=0Yes
ADDIUGPR <d>, UIMM16 <i>0x08x=0,f=1,h=0Yes
ADDIHGPR <d>, UIMM16 <i>0x08x=0,f=1,h=1Yes
ADDIHGPR <d>, SIMM16 <i>0x08x=0,f=1,h=1No
ADDIUFGPR <d>, UIMM16 <i>0x08x=0,f=0,h=0Yes
ADDIHFGPR <d>, UIMM16 <i>0x08x=0,f=0,h=1Yes
ADDIHFGPR <d>, SIMM16 <i>0x08x=0,f=0,h=1No
INCGPR <d>0x08x=0,f=1,h=0,i=1No
DECGPR <d>0x08x=1,f=1,h=0,i=0xFFFFNo

Arithmetic Ops

MnemonicOperandsOpcodeSpecial Payload EncodingCanonical
ADDGPR <d>, SGPR <a> << <s>, GPR <b>0x09f=1,p=0Yes
ADDGPR <d>, GPR <a>, SGPR <b> << <s>0x09f=1,p=1Yes
ADDGPR <d>, GPR <a>, GPR <b>0x09f=1,p=0,s=0No
ADDFGPR <d>, SGPR <a> << <s>, GPR <b>0x09f=0,p=0Yes
ADDFGPR <d>, GPR <a>, SGPR <b> << <s>0x09f=0,p=1Yes
ADDFGPR <d>, GPR <a>, GPR <b>0x09f=0,p=0,s=0No
SUBGPR <d>, SGPR <a> << <s>, GPR <b>0x0Af=1,p=0Yes
SUBGPR <d>, GPR <a>, SGPR <b> << <s>0x0Af=1,p=1Yes
SUBGPR <d>, GPR <a>, GPR <b>0x0Af=1,p=0,s=0No
SUBFGPR <d>, SGPR <a> << <s>, GPR <b>0x0Af=0,p=0Yes
SUBFGPR <d>, GPR <a>, SGPR <b> << <s>0x0Af=0,p=1Yes
SUBFGPR <d>, GPR <a>, GPR <b>0x0Af=0,p=0,s=0No
CMPSGPR <a> << <s>, GPR <b>0x0Af=0,p=0,d=0No
CMPGPR <a>, SGPR <b> << <s>0x0Af=0,p=1,d=0No
CMPGPR <a>, GPR <b>0x0Af=0,p=0,s=0,d=0No
SHLGPR <d>, GPR <a>, ABSIMM5 <s>0x09f=1,p=0,b=0No
SHLFGPR <d>, GPR <a>, ABSIMM5 <s>0x09f=2,p=0,b=0No

Logic Ops

MnemonicOperandsOpcodeSpecial Payload EncodingCanonical
ANDGPR <d>, SIGPR <i> <a> << <s>, IGPR <j> <b>0x0Bf=1,p=0Yes
ANDGPR <d>, IGPR <i> <a>, SIGPR <j><b> << <s>0x0Bf=1,p=1Yes
ANDGPR <d>, IGPR <i> <a>, GPR <j> <b>0x0Bf=1,p=0,s=0No
ANDFGPR <d>, SIGPR <i> <a> << <s>, IGPR <j> <b>0x0Bf=0,p=0Yes
ANDFGPR <d>, IGPR <i> <a>, SIGPR <j><b> << <s>0x0Bf=0,p=1Yes
ANDFGPR <d>, IGPR <i> <a>, GPR <j> <b>0x0Bf=0,p=0,s=0No
ORGPR <d>, SIGPR <i> <a> << <s>, IGPR <j> <b>0x0Cf=1,p=0Yes
ORGPR <d>, IGPR <i> <a>, SIGPR <j><b> << <s>0x0Cf=1,p=1Yes
ORGPR <d>, IGPR <i> <a>, GPR <j> <b>0x0Cf=1,p=0,s=0No
ORFGPR <d>, SIGPR <i> <a> << <s>, IGPR <j> <b>0x0Cf=0,p=0Yes
ORFGPR <d>, IGPR <i> <a>, SIGPR <j><b> << <s>0x0Cf=0,p=1Yes
ORFGPR <d>, IGPR <i> <a>, GPR <j> <b>0x0Cf=0,p=0,s=0No
XORGPR <d>, SIGPR <i> <a> << <s>, IGPR <j> <b>0x0Df=1,p=0Yes
XORGPR <d>, IGPR <i> <a>, SIGPR <j><b> << <s>0x0Df=1,p=1Yes
XORGPR <d>, IGPR <i> <a>, GPR <j> <b>0x0Df=1,p=0,s=0No
XORFGPR <d>, SIGPR <i> <a> << <s>, IGPR <j> <b>0x0Df=0,p=0Yes
XORFGPR <d>, IGPR <i> <a>, SIGPR <j><b> << <s>0x0Df=0,p=1Yes
XORFGPR <d>, IGPR <i> <a>, GPR <j> <b>0x0Df=0,p=0,s=0No
TESTSIGPR <i> <a> << <s>, IGPR <j> <b>0x0Bf=1,p=0,d=0No
TESTIGPR <i> <a>, SIGPR <j><b> << <s>0x0Bf=1,p=1,d=0No
TESTIGPR <i> <a>, GPR <j> <b>0x0Bf=1,p=0,s=0,d=0No

Shifts

MnemonicOperandsOpcodeSpecial Payload EncodingCanonical
BSLGPR <d>, GPR <v>, GPR <q>, GPR <r>0x0Ew=0, x=0,c=1Yes
BSLWGPR <d>, GPR <v>, GPR <q>, GPR <r>0x0Ew=1, x=0, c=1Yes
BSLFGPR <d>, GPR <v>, GPR <q>, GPR <r>0x0Ew=0,x=0,f=0Yes
BSLWFGPR <d>, GPR <v>, GPR <q>, GPR <r>0x0Ew=1,x=0,f=0Yes
XBSLGPR <d>, GPR <v>, GPR <q>, GPR <r>0x0Ew=0, x=1,c=1Yes
XBSLWGPR <d>, GPR <v>, GPR <q>, GPR <r>0x0Ew=1, x=1, c=1Yes
XBSLFGPR <d>, GPR <v>, GPR <q>, GPR <r>0x0Ew=0,x=1,f=0Yes
XBSLWFGPR <d>, GPR <v>, GPR <q>, GPR <r>0x0Ew=1,x=1,f=0Yes
SHLGPR <d>, GPR <v>, GPR <q>0x0Ew=0,x=0,c=1,r=0No
SHLWGPR <d>, GPR <v>, GPR <q>0x0Ew=1,x=0,c=1,r=0No
SHLFGPR <d>, GPR <v>, GPR <q>0x0Ew=0,x=0,f=0,r=0No
SHLWFGPR <d>, GPR <v>, GPR <q>0x0Ew=1,x=0,f=0,r=0No
ROLGPR <d>, GPR <v>, GPR <q>0x0Ew=1,x=0,c=1,r=vNo
ROLFGPR <d>, GPR <v>, GPR <q>0x0Ew=1,x=0,f=0,r=vNo
BSRGPR <d>, GPR <v>, GPR <q>, GPR <r>0x0Fw=0, x=0,c=1Yes
BSRWGPR <d>, GPR <v>, GPR <q>, GPR <r>0x0Fw=1, x=0, c=1Yes
BSRFGPR <d>, GPR <v>, GPR <q>, GPR <r>0x0Fw=0,x=0,f=0Yes
BSRWFGPR <d>, GPR <v>, GPR <q>, GPR <r>0x0Fw=1,x=0,f=0Yes
XBSRGPR <d>, GPR <v>, GPR <q>, GPR <r>0x0Fw=0, x=1,c=1Yes
XBSRWGPR <d>, GPR <v>, GPR <q>, GPR <r>0x0Fw=1, x=1, c=1Yes
XBSRFGPR <d>, GPR <v>, GPR <q>, GPR <r>0x0Fw=0,x=1,f=0Yes
XBSRWFGPR <d>, GPR <v>, GPR <q>, GPR <r>0x0Fw=1,x=1,f=0Yes
SHRGPR <d>, GPR <v>, GPR <q>0x0Fw=0,x=0,c=1,r=0No
SHRWGPR <d>, GPR <v>, GPR <q>0x0Fw=1,x=0,c=1,r=0No
SHRFGPR <d>, GPR <v>, GPR <q>0x0Fw=0,x=0,f=0,r=0No
SHRWFGPR <d>, GPR <v>, GPR <q>0x0Fw=1,x=0,f=0,r=0No
RORGPR <d>, GPR <v>, GPR <q>0x0Fw=1,x=0,c=1,r=vNo
ROLRCGPR <d>, GPR <v>, GPR <q>0x0Fw=1,x=0,f=0,r=vNo
SARGPR <d>, GPR <v>, GPR <q>0x0Fw=0,x=1,c=1,r=0No
SARWGPR <d>, GPR <v>, GPR <q>0x0Fw=1,x=1,c=1,r=0No
SARFGPR <d>, GPR <v>, GPR <q>0x0Fw=0,x=1,f=0,r=0No
SARWFGPR <d>, GPR <v>, GPR <q>0x0Fw=1,x=1,f=0,r=0No

Branches

MnemonicOperandsOpcodeSpecial Payload EncodingCanonical
JL<c>GPR <l>, OFF15 <o>0x10-Yes
JLR<c>GPR <l>, GPR <r>0x11-Yes
JMP<c>OFF15 <o>0x10l=0No
JMPR<c>GPR <r>0x11l=0No
JMPOFF15 <o>0x10l=0,c=15No
JMPRGPR <r>0x11l=0,c=15No
CALLGPR <l>, OFF16 <o>0x10c=15No
CALLRGPR <l>, GPR <r>0x11c=15No
CALLOFF16 <o>0x10l=31,c=15No
CALLRGPR <r>0x11l=31,c=15No
IRETPRIO <p>0x12-Yes

I/O Transfers

MnemonicOperandsOpcodeSpecial Payload EncodingCanonical
INIOR <d>, ABSIMM8 <p>, BITW <w>0x14-Yes
OUTIOR <s>, ABSIMM8 <p>, BITW <w>0x15-Yes

Flags Manipulation

MnemonicOperandsOpcodeSpecial Payload EncodingCanonical
LDFLAGSGPR <d>, ABSIMM5 <f>0x18-Yes
LDFLAGSGPR <d>0x18f=0x1FNo
STFLAGSGPR <s>, ABSIMM5 <f>0x19-Yes
STFLAGSGPR <s>0x19f=0x1FNo
XVP-0x1A-Yes

Exchange Register Contents

MnemonicOperandsOpcodeSpecial Payload EncodingCanonical
XCHG<c>GPR <a>, GPR <b>0x1Cl=0Yes
XCHGL<c>GPR <a>, GPR <b>0x1Cl=1Yes
XCHGGPR <a>, GPR <b>0x1Cc=15,l=1No

Extend Register Contents

MnemonicOperandsOpcodeSpecial Payload EncodingCanonical
EXTSGPR <d>, GPR <s>, BITW <w>0x1Dx=1Yes
EXTZGPR <d>, GPR <s>, BITW <w>0x1Dx=0Yes

Random Bit Generation

MnemonicOperandsOpcodeSpecial Payload EncodingCanonical
RBGENGPR <d>, GPR <e>, BITW <w>0x1E-Yes
RBGENGPR <d>, BITW <w>0x1Ee=0No
RBGENGPR <d>, GPR <e>0x1Ew=0No
RBGENGPR <d>0x1Ee=0,w=0No

Coprocessor Invocations

MnemonicOperandsOpcodeSpecial Payload EncodingCanonical
CPI<x>ABSIMM4 <f>, VPAYLOAD20 <p>0x20+x-Yes
CPI<x>EFABSIMM6 <f>, VPAYLOAD18 <p>0x28+x-Yes
NCPI<x>ABSIMM4 <f>, VPAYLOAD20 <p>0x30+x-Yes
NCPI<x>EFABSIMM6 <f>, VPAYLOAD20 <p>0x38+x-Yes

Stop/Halt

MnemonicOperandsOpcodeSpecial Payload EncodingCanonical
HLT-0x40-Yes
STP-0x41-Yes

Psuedo-instructions

Certain Menmonics assembly to a special sequence of instructions and to a link relaxation. These are expressed using macro assembly syntax, but are expected to be treated as intrinsics.

LDIW

.macro ldiw GPR <reg>, UIMM32 <val>
    ; Emits R_SKYARCH_RELAX16_32 if `val` is a symbol
    ldiu <reg>, <val>@LO
    addih <reg>, <val>@HI
.endmacro

.macro ldiw GPR <reg>, SIMM32 <val>
    ; Emits R_SKYARCH_RELAX16_32 if `val` is a symbol
    ldiu <reg>, <val>@LO
    addih <reg>, <val>@HI
.endmacro

May be converted to either ldi <reg>, <val> if the value is known to be in range

LRAW

Loads a wide relative address

.macro lraw GPR <reg>, PCREL32 <val>
    ; Emits R_SKYARCH_RELAX16_PC32 if `val` is a symbol
    lrau <reg>, <val>@LO
    addih <reg>, <val>@HI
.endmacro

may be converted to lra <reg>, val if the value is known to be in range

JMPW/JLW/CALLW

.macro jl<cc>w GPR <link>, PCREL32 <val>, GPR <scratch>=r15
    ; Emits R_SKYARCH_RELAXJMPOFF_PC32 if `val` is a symbol
    lraw <scratch>, <val>
    jlr<cc> <link>, <scratch>
.endmacro

.macro jlw GPR <link>, PCREL32 <val>, GPR <scratch>=r15
    jlalw <link>, <val>, <scratch>
.endmacro

.macro jmp<cc>w PCREL32 <val>, GPR <scratch>=r15
    jl<cc>w r0, <val>, <scratch>
.endmacro

.macro jmpw PCREL32 <val>, GPR <scratch>=r15
    jlw r0, <val>, <scratch>
.endmacro

.macro callw PCREL32, GPR <scratch>=r15
    jlw r31, <val>, <scratch>
.endmacro

May be converted to jl<cc> (as appropriate) if val is known to be in range. The value of <scratch> after the psuedo-instruction completes is unspecified (may not have been modified, or may be loaded with any value).