homebusinessblogart

Uxn Basics

About

"Uxn is a virtual machine with 32 instructions.
This one-page computer is capable of hosting small applications, programmable in a unique language. It was designed with an implementation-first mindset with a focus on creating portable tools and games." - xxiivv/uxn

Resources

1. Compudanza's Tutorial
2. Metasyn's Learn Uxn for getting your hands dirty, quick

Notes

1. Literal hex run (#) -- an alternative to 'LIT'
2. Raw character rune (')
3. Runes for laberls (@ and &)
4. Macros (%)

Lesson 1 - "hello"

1. Output "hello" code

( hello.tal )
|0100 LIT 68 LIT 18 DEO ( h )
LIT 65 LIT 18 DEO ( e )
LIT 6c LIT 18 DEO ( l )
LIT 6c LIT 18 DEO ( l )
LIT 6f LIT 18 DEO ( o )
LIT 0a LIT 18 DEO ( newline )

+ Console Output: "hello"

2. Output "hello" code with literal rune (#)

( hello.tal )
|0100 #68 #18 DEO ( h )
#65 #18 DEO ( e )
#6c #18 DEO ( l )
#6c #18 DEO ( l )
#6f #18 DEO ( o )
#0a #18 DEO ( newline )

+ Console Output: "hello"

3. Output "hello" code with raw character rune (')

( hello.tal )
|0100 LIT 'h #18 DEO
LIT 'e #18 DEO
LIT 'l #18 DEO
LIT 'l #18 DEO
LIT 'o #18 DEO
#0a #18 DEO ( newline )

+ Console Output: "hello"

4. Output "hello" code with runes for labels (@ and &)

( hello.tal )
( devices )
|10 @Console [ &vector $2 &read $1 &pad $5 &write $1 &error $1 ]

( main program )
|0100 LIT 'h .Console/write DEO
LIT 'e .Console/write DEO
LIT 'l .Console/write DEO
LIT 'l .Console/write DEO
LIT 'o .Console/write DEO
#0a .Console/write DEO ( newline )

+ Console Output: "hello"

5. Output "hello" with macros (%)

( hello.tal )
( devices )
|10 @Console [ &vector $2 &read $1 &pad $5 &write $1 &error $1 ]

( macros )
( print a character to standard output )
%EMIT { .Console/write DEO } ( character -- )
( print a newline )
%NL { #0a EMIT } ( -- )

( main program )
|0100 LIT 'h EMIT
LIT 'e EMIT
LIT 'l EMIT
LIT 'l EMIT
LIT 'o EMIT
NL





Exercise Q2:

%EMIT { .Console/write DEO }
%PRINT-DIGIT { #30 ADD EMIT } ( number -- )
%NL { #0a EMIT }
( main program )
|0100
#03 PRINT-DIGIT
NL

Lesson 2 -