Skip to content

Instantly share code, notes, and snippets.

@Ismael-VC
Created April 2, 2023 23:13
Show Gist options
  • Save Ismael-VC/2c983ea571f86678756c00d8899e2c0b to your computer and use it in GitHub Desktop.
Save Ismael-VC/2c983ea571f86678756c00d8899e2c0b to your computer and use it in GitHub Desktop.
UXN Tutorial: Day 1
( hello.tal )
(
@|devices )
|10 @Console [
&vector $2
&read $1
&pad $5
&write $1
&error $1
]
(
@|macros )
%EMIT { .Console/write DEO } ( char -- )
%CALL { JSR2 }
%RTN { JMP2r }
%HALT { #010f DEO } ( -- )
%\n { 0a }
%\0 { 00 }
%PRINT-DIGIT { #30 ADD EMIT } ( number -- )
(
@|init )
|0100 ( -> )
( Outputs: hello!\n )
( All these are the same! )
LIT 68 LIT 18 DEO ( h )
#65 #18 DEO ( e )
#6c18 DEO ( l )
LIT "l LIT 18 DEO ( l )
LIT "o .Console/write DEO ( o )
LIT "! EMIT ( ! )
80 0a 80 18 17 ( \n )
( Outputs: hello!\n )
80 68 80 18 17 ( h )
80 65 80 18 17 ( e )
80 6c 80 18 17 ( l )
80 6c 80 18 17 ( l )
80 6f 80 18 17 ( o )
80 21 80 18 17 ( ! )
80 0a 80 18 17 ( \n )
( Outputs: hello!\n )
( Call: print-str(hello: ptr*) -> void )
;hello print-str
[ ;hello ] print-str
;hello ;print-str CALL
( Outputs: hello!\n )
( wst: \n ! o l l e h )
LIT 0a LIT "! LIT "o LIT "l LIT "l LIT "e LIT "h
EMIT EMIT EMIT EMIT EMIT EMIT EMIT
#05 PRINT-DIGIT
LIT \n EMIT
HALT
BRK
(
@|routines )
@print-str ( str* -- )
&loop
LDAk EMIT
INC2 LDAk ?&loop
POP2
RTN
@print-digits ( list* -- )
&loop
LDAk PRINT-DIGIT
INC LDAk ?&loop
POP
RTN
(
@|data )
@hello "hello! \n \0
@list [ 00 01 02 03 04 05 06 07 08 09 ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment