uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

subleq.tal (1076B)


      1 ( Subleq: The subleq instruction subtracts the contents at address a from the contents at address b, stores the result at address b, and then, if the result is not positive, jumps to address c. If the result is positive, execution proceeds to the next instruction in sequence. )
      2 
      3 |0100
      4 
      5 @on-reset ( -> )
      6 	#0000
      7 	&while ( -- )
      8 		eval DUP2 #8000 LTH2 ?&while
      9 	POP2
     10 	( halt ) #010f DEO
     11 	BRK
     12 
     13 @eval ( ip* -- ip* )
     14 	DUP2 get ,&a STR2
     15 	INC2 DUP2 get ,&b STR2
     16 	INC2 DUP2 get ,&c STR2
     17 	INC2
     18 	( | I/O )
     19 	[ LIT2 &a $2 ] #ffff EQU2 ?&input
     20 	[ LIT2 &b $2 ] #ffff EQU2 ?&output
     21 	( | SUBLEQ )
     22 	( sub ) ,&b LDR2 get ,&a LDR2 get SUB2 DUP2
     23 	( write ) ,&b LDR2 DUP2 ADD2 ;program ADD2 STA2
     24 	( leq ) #0001 SUB2 #8000 LTH2 ?&end
     25 	POP2 [ LIT2 &c $2 ] &end JMP2r
     26 	&input ( -- )
     27 		( TODO ) JMP2r
     28 	&output ( -- )
     29 		,&a LDR2 get NIP #18 DEO
     30 		JMP2r
     31 
     32 @get ( a* -- b* )
     33 	DUP2 ADD2 ;program ADD2 LDA2 JMP2r
     34 
     35 @program ( hello world )
     36 	[
     37 	000f 0011 ffff 0011 ffff ffff 0010 0001
     38 	ffff 0010 0003 ffff 000f 000f 0000 0000
     39 	ffff 0048 0065 006c 006c 006f 002c 0020
     40 	0077 006f 0072 006c 0064 0021 000a 0000 ]
     41