XXIIVV

Uxntal Opcodes

Uxn has 64kb of memory, 16 devices, 2 stacks of 256 bytes, 5-bits opcodes and 3 modes. The list below show the standard opcodes and their effect on a given stack a b c. PC: Program Counter, |: Return Stack, [M]: Memory, [D+*]: Device Memory, a8: a byte, a16: a short.

LIT a b c [PC]
JCI a b (c8)PC+=[PC]
JMI a b c PC+=[PC]
JSI a b c | PC PC+=[PC]

BRK .        EQU a b==c          LDZ a b [c8]     ADD a b+c
INC a b c+1  NEQ a b!=c          STZ a [c8]=b     SUB a b-c
POP a b      GTH a b>c           LDR a b [PC+c8]  MUL a b*c
NIP a c      LTH a b<c           STR a [PC+c8]=b  DIV a b/c
SWP a c b    JMP a b PC+=c       LDA a b [c16]    AND a b&c
ROT b c a    JCN a (b8)PC+=c     STA a [c16]=b    ORA a b|c
DUP a b c c  JSR a b | PC PC+=c  DEI a b [D+c8]   EOR a b^c
OVR a b c b  STH a b | c         DEO a [D+c8]=b   SFT a b>>c8l<<c8h

To learn more about each opcode, see the Opcode Reference.

The Uxntal Opcode Reference

This documentation includes hand gestures, and glyphs, which might serve a dual purpose; both enabling the usage of Uxntal outside of the computer, as well as to help students to familiarize themselves with hexadecimal finger-counting and bitwise operations.

000102030405060708090a0b0c0d0e0f
00 BRK INC POP NIP SWP ROT DUP OVR EQU NEQ GTH LTH JMP JCN JSR STH
10 LDZ STZ LDR STR LDA STA DEI DEO ADD SUB MUL DIV AND ORA EOR SFT
20JCIINC2POP2NIP2SWP2ROT2DUP2OVR2EQU2NEQ2GTH2LTH2JMP2JCN2JSR2STH2
30LDZ2STZ2LDR2STR2LDA2STA2DEI2DEO2ADD2SUB2MUL2DIV2AND2ORA2EOR2SFT2
40JMIINCrPOPrNIPrSWPrROTrDUPrOVRrEQUrNEQrGTHrLTHrJMPrJCNrJSRrSTHr
50LDZrSTZrLDRrSTRrLDArSTArDEIrDEOrADDrSUBrMULrDIVrANDrORArEORrSFTr
60JSIINC2rPOP2rNIP2rSWP2rROT2rDUP2rOVR2rEQU2rNEQ2rGTH2rLTH2rJMP2rJCN2rJSR2rSTH2r
70LDZ2rSTZ2rLDR2rSTR2rLDA2rSTA2rDEI2rDEO2rADD2rSUB2rMUL2rDIV2rAND2rORA2rEOR2rSFT2r
80LITINCkPOPkNIPkSWPkROTkDUPkOVRkEQUkNEQkGTHkLTHkJMPkJCNkJSRkSTHk
90LDZkSTZkLDRkSTRkLDAkSTAkDEIkDEOkADDkSUBkMULkDIVkANDkORAkEORkSFTk
a0LIT2INC2kPOP2kNIP2kSWP2kROT2kDUP2kOVR2kEQU2kNEQ2kGTH2kLTH2kJMP2kJCN2kJSR2kSTH2k
b0LDZ2kSTZ2kLDR2kSTR2kLDA2kSTA2kDEI2kDEO2kADD2kSUB2kMUL2kDIV2kAND2kORA2kEOR2kSFT2k
c0LITrINCkrPOPkrNIPkrSWPkrROTkrDUPkrOVRkrEQUkrNEQkrGTHkrLTHkrJMPkrJCNkrJSRkrSTHkr
d0LDZkrSTZkrLDRkrSTRkrLDAkrSTAkrDEIkrDEOkrADDkrSUBkrMULkrDIVkrANDkrORAkrEORkrSFTkr
e0LIT2rINC2krPOP2krNIP2krSWP2krROT2krDUP2krOVR2krEQU2krNEQ2krGTH2krLTH2krJMP2krJCN2krJSR2krSTH2kr
f0LDZ2krSTZ2krLDR2krSTR2krLDA2krSTA2krDEI2krDEO2krADD2krSUB2krMUL2krDIV2krAND2krORA2krEOR2krSFT2kr

In the a b -- c d notation, "a b" represent the state of the stack before the operation, "c d" represent the state after the operation, with "b" and "d" on top of the stack, respectively.

Break

BRK -- Ends the evalutation of the current vector. This opcode has no modes.

Jump Conditional Instant

JCI cond8 -- Pops a byte from the working stack and if it is not zero, moves the PC to a relative address at a distance equal to the next short in memory, otherwise moves PC+2. This opcode has no modes.

Jump Instant

JMI -- Moves the PC to a relative address at a distance equal to the next short in memory. This opcode has no modes.

Jump Stash Return Instant

JSI -- Pushes PC+2 to the return-stack and moves the PC to a relative address at a distance equal to the next short in memory. This opcode has no modes.

Literal

LIT -- a Pushes the next bytes in memory, and moves the PC+2. The LIT opcode always has the keep mode active. Notice how the 0x00 opcode, with the keep bit toggled, is the location of the literal opcodes.

LIT 12          ( 12 )
LIT2 abcd       ( ab cd )

Increment

INC a -- a+1 Increments the value at the top of the stack, by 1.

#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 )

Nip

NIP a b -- b Removes the second value from the stack. This is practical to convert a short into a byte.

#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 )

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 )

Duplicate

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

#1234 DUP   ( 12 34 34 )
#12 DUPk    ( 12 12 12 )
#1234 DUP2  ( 12 34 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 )

Equal

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

#1212 EQU          ( 01 )
#1234 EQUk         ( 12 34 00 )
#abcd #ef01 EQU2   ( 00 )
#abcd #abcd EQU2k  ( ab cd ab cd 01 )

Not Equal

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

#1212 NEQ          ( 00 )
#1234 NEQk         ( 12 34 01 )
#abcd #ef01 NEQ2   ( 01 )
#abcd #abcd NEQ2k  ( ab cd ab cd 00 )

Greater Than

GTH a b -- bool8 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.

#1234 GTH          ( 00 )
#3412 GTHk         ( 34 12 01 )
#3456 #1234 GTH2   ( 01 )
#1234 #3456 GTH2k  ( 12 34 34 56 00 )

Lesser Than

LTH a b -- bool8 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 )

Jump

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

,&skip-rel JMP BRK &skip-rel #01  ( 01 )

Jump Conditional

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

#abcd #01 ,&pass JCN SWP &pass POP  ( ab )
#abcd #00 ,&fail JCN SWP &fail POP  ( cd )

Jump Stash Return

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

,&routine JSR                     ( | PC* )
,&get JSR #01 BRK &get #02 JMP2r  ( 02 01 )

Stash

STH a -- | a Moves the value at the top of the stack to the return stack. Note that with the r-mode, the stacks are exchanged and the value is moved from the return stack to the working stack.

#12 STH       ( | 12 )
LITr 34 STHr  ( 34 )

Load Zero-Page

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

|00 @cell $2 |0100 .cell LDZ ( 00 )

Store Zero-Page

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

|00 @cell $2 |0100 #abcd .cell STZ2  { ab cd }

Load Relative

LDR addr8 -- value Pushes a value at a relative address in relation to the PC, within a range between -128 and +127 bytes, to the top of the stack.

,cell LDR2 BRK @cell abcd  ( ab cd )

Store Relative

STR val addr8 -- Writes a value to a relative address in relation to the PC, within a range between -128 and +127 bytes.

#1234 ,cell STR2 BRK @cell $2  ( )

Load Absolute

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

;cell LDA BRK @cell abcd ( ab )

Store Absolute

STA val addr16 -- Writes a value to a absolute address.

#abcd ;cell STA BRK @cell $1 ( ab )

Device Input

DEI device8 -- value Pushes a value from the device page, to the top of the stack. The target device might capture the reading to trigger an I/O event.

Device Output

DEO val device8 -- Writes a value to the device page. The target device might capture the writing to trigger an I/O event.


Add

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

#1a #2e ADD       ( 48 )
#02 #5d ADDk      ( 02 5d 5f )
#0001 #0002 ADD2  ( 00 03 )

Subtract

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

Multiply

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

Divide

DIV a b -- a/b Pushes the quotient of the first value over the second, to the top of the stack. A division by zero pushes zero on the stack. The rounding direction is toward zero.

#10 #02 DIV       ( 08 )
#10 #03 DIVk      ( 10 03 05 )
#0010 #0000 DIV2  ( 00 00 )

And

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

Or

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

Exclusive Or

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

Shift

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

#34 #10 SFT        ( 68 )
#34 #01 SFT        ( 1a )
#34 #33 SFTk       ( 34 33 30 )
#1248 #34 SFTk2    ( 12 48 34 09 20 )

incoming uxn uxntal syntax uxntal syntax uxntal syntax uxntal syntax uxntal syntax