XXIIVV

The Uxntal Opcode Manual

The LIT and BRK opcodes share the same opcode space, the BRK opcode is stored as 00, whereas the LIT and LIT2 opcodes are stored where LITk and LIT2k would be stored. The extra modes of the BRK/LIT opcode are unused.

000102030405060708090a0b0c0d0e0f
00BRKINCPOPDUPNIPSWPOVRROTEQUNEQGTHLTHJMPJCNJSRSTH
10LDZSTZLDRSTRLDASTADEIDEOADDSUBMULDIVANDORAEORSFT
20---INC2POP2DUP2NIP2SWP2OVR2ROT2EQU2NEQ2GTH2LTH2JMP2JCN2JSR2STH2
30LDZ2STZ2LDR2STR2LDA2STA2DEI2DEO2ADD2SUB2MUL2DIV2AND2ORA2EOR2SFT2
40---INCrPOPrDUPrNIPrSWPrOVRrROTrEQUrNEQrGTHrLTHrJMPrJCNrJSRrSTHr
50LDZrSTZrLDRrSTRrLDArSTArDEIrDEOrADDrSUBrMULrDIVrANDrORArEORrSFTr
60---INC2rPOP2rDUP2rNIP2rSWP2rOVR2rROT2rEQU2rNEQ2rGTH2rLTH2rJMP2rJCN2rJSR2rSTH2r
70LDZ2rSTZ2rLDR2rSTR2rLDA2rSTA2rDEI2rDEO2rADD2rSUB2rMUL2rDIV2rAND2rORA2rEOR2rSFT2r
80LITINCkPOPkDUPkNIPkSWPkOVRkROTkEQUkNEQkGTHkLTHkJMPkJCNkJSRkSTHk
90LDZkSTZkLDRkSTRkLDAkSTAkDEIkDEOkADDkSUBkMULkDIVkANDkORAkEORkSFTk
a0LIT2INC2kPOP2kDUP2kNIP2kSWP2kOVR2kROT2kEQU2kNEQ2kGTH2kLTH2kJMP2kJCN2kJSR2kSTH2k
b0LDZ2kSTZ2kLDR2kSTR2kLDA2kSTA2kDEI2kDEO2kADD2kSUB2kMUL2kDIV2kAND2kORA2kEOR2kSFT2k
c0LITrINCrkPOPrkDUPrkNIPrkSWPrkOVRrkROTrkEQUrkNEQrkGTHrkLTHrkJMPrkJCNrkJSRrkSTHrk
d0LDZrkSTZrkLDRrkSTRrkLDArkSTArkDEIrkDEOrkADDrkSUBrkMULrkDIVrkANDrkORArkEORrkSFTrk
e0LIT2rINC2rkPOP2rkDUP2rkNIP2rkSWP2rkOVR2rkROT2rkEQU2rkNEQ2rkGTH2rkLTH2rkJMP2rkJCN2rkJSR2rkSTH2rk
f0LDZ2rkSTZ2rkLDR2rkSTR2rkLDA2rkSTA2rkDEI2rkDEO2rkADD2rkSUB2rkMUL2rkDIV2rkAND2rkORA2rkEOR2rkSFT2rk

Instructions

Break

BRK -- Halts the program. Further instructions will not be run.

Literal

LIT -- a Pushes the next value seen in the program onto the stack.

Increment

INC a -- b Adds 1 to the value at the top of the stack.

#01 INC         ( 02 )
#0001 INC2      ( 00 02 )
#0001 INC2k     ( 00 01 00 02 )

Pop

POP a -- Removes the value at the top of the stack.

#1234 POP    ( 12 )
#1234 POP2   ( )
#1234 POP2k  ( 12 34 )

Duplicate

DUP a -- a Duplicates the value at the top of the stack.

#1234 DUP   ( 12 34 34 )
#1234 DUP2  ( 12 34 12 34 )

Nip

NIP a b -- b Removes the second value from the stack.

#1234 NIP          ( 34 )
#1234 #5678 NIP2   ( 56 78 )
#1234 #5678 NIP2k  ( 12 34 56 78 56 78 )

Swap

SWP a b -- b a Exchanges the first and second values at the top of the stack.

#1234 SWP          ( 34 12 )
#1234 SWPk         ( 12 34 34 12 )
#1234 #5678 SWP2   ( 56 78 12 34 )
#1234 #5678 SWP2k  ( 12 34 56 78 56 78 12 34 )

Over

OVR a b -- a b a Duplicates the second value at the top of the stack.

#1234 OVR          ( 12 34 12 )
#1234 OVRk         ( 12 34 12 34 12 )
#1234 #5678 OVR2   ( 12 34 56 78 12 34 )
#1234 #5678 OVR2k  ( 12 34 56 78 12 34 56 78 12 34 )

Rotate

ROT a b c -- b c a Rotates three values at the top of the stack, to the left, wrapping around.

#1234 #56 ROT            ( 34 56 12 )
#1234 #56 ROTk           ( 12 34 56 34 56 12 )
#1234 #5678 #9abc ROT2   ( 56 78 9a bc 12 34 )
#1234 #5678 #9abc ROT2k  ( 12 34 56 78 9a bc 56 78 9a bc 12 34 )

Logic

Equal

EQU a b -- bool^ Pushes 01 to the stack if the two values at the top of the stack are equal, 00 otherwise.

#0101 EQU          ( 01 )
#0100 EQUk         ( 01 00 00 )
#0001 #0000 EQU2   ( 00 )
#0001 #0000 EQU2k  ( 00 01 00 00 00 )

Not Equal

NEQ a b -- bool^ Pushes 01 to the stack if the two values at the top of the stack are not equal, 00 otherwise.

#0101 NEQ          ( 00 )
#0100 NEQk         ( 01 00 01 )
#0001 #0000 NEQ2   ( 01 )
#0001 #0000 NEQ2k  ( 00 01 00 00 01 )

Greater Than

GTH a b -- bool^ Pushes 01 to the stack if the second value at the top of the stack is greater than the value at the top of the stack, 00 otherwise.

#0101 GTH          ( 00 )
#0100 GTHk         ( 01 00 01 )
#0001 #0000 GTH2   ( 01 )
#0001 #0000 GTH2k  ( 00 01 00 00 01 )

Lesser Than

LTH a b -- bool^ Pushes 01 to the stack if the second value at the top of the stack is lesser than the value at the top of the stack, 00 otherwise.

#0101 LTH          ( 00 )
#0100 LTHk         ( 01 00 00 )
#0001 #0000 LTH2   ( 00 )
#0001 #0000 LTH2k  ( 00 01 00 00 00 )

Control-Flow

Jump

JMP addr -- Moves the program counter by a signed value equal to the byte on the top of the stack, or an absolute address in short mode.

Jump Conditional

JCN bool^ addr -- If the byte preceeding the address is not 00, moves the program counter by a signed value equal to the byte on the top of the stack, or an absolute address in short mode.

Jump Stash Return

JSR addr -- Pushes the value of the program counter to the return-stack and moves the program counter by a signed value equal to the byte on the top of the stack, or an absolute address in short mode.

Stash

STH a -- Moves the value at the top of the stack, to the return stack.

Memory

Load Zero-Page

LDZ addr^ -- value Pushes the value at an address within the first 256 bytes of memory, to the top of the stack.

Store Zero-Page

STZ val addr^ -- Writes a value to an address within the first 256 bytes of memory.

Load Relative

LDR addr^ -- value Pushes the value at a relative address, to the top of the stack. The possible relative range is -128 to +127 bytes.

Store Relative

STR val addr^ -- Writes a value to a relative address. The possible relative range is -128 to +127 bytes.

Load Absolute

LDA addr* -- value Pushes the value at a absolute address, to the top of the stack.

Store Absolute

STA val addr* -- Writes a value to a absolute address.

Arithmetic

Add

ADD a b -- c Pushes the sum of the two values at the top of the stack.

Subtract

SUB a b -- c Pushes the difference of the first value minus the second, to the top of the stack.

Multiply

MUL a b -- c Pushes the product of the first and second values at the top of the stack.

Divide

DIV a b -- c Pushes the quotient of the first value over the second, to the top of the stack.

Bitwise

And

AND a b -- c Pushes the result of the bitwise operation AND, to the top of the stack.

Or

ORA a b -- c Pushes the result of the bitwise operation OR, to the top of the stack.

Exclusive Or

EOR a b -- c Pushes the result of the bitwise operation XOR, to the top of the stack.

Shift

SFT a b^ -- c Moves the bits of the value at the top of the stack to the left or right, depending on the control value of the second. The high nibble of the control value determines how many bits left to shift, and the low nibble how many bits right to shift. The rightward shift is done first.