about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorelioat <elioat@tilde.institute>2022-10-08 00:41:44 +0000
committerelioat <elioat@tilde.institute>2022-10-08 00:41:44 +0000
commitc276f8d4ddd40d2eb159eb77a154adb6b8fe970a (patch)
tree2e8c45829d5d7c2476b43cdd16f276360bdcfbf6
parent47f67f9dbef72a74dfb24c6bb716c64377406a20 (diff)
downloadtour-c276f8d4ddd40d2eb159eb77a154adb6b8fe970a.tar.gz
*
-rwxr-xr-xuxntal/build.sh6
-rw-r--r--uxntal/fib.tal22
-rw-r--r--uxntal/hi.rombin31 -> 0 bytes
-rw-r--r--uxntal/primes.tal42
4 files changed, 69 insertions, 1 deletions
diff --git a/uxntal/build.sh b/uxntal/build.sh
index f79bdca..10cc8b4 100755
--- a/uxntal/build.sh
+++ b/uxntal/build.sh
@@ -1,5 +1,9 @@
 #!/bin/ksh
 
-rm hi.rom
+rm hi.rom fib.rom primes.rom
 u uxnasm hi.tal hi.rom
+u drifblim fib.tal fib.rom
+u drifblim primes.tal primes.rom
 u uxncli hi.rom
+u uxncli fib.rom
+# u uxncli primes.rom
diff --git a/uxntal/fib.tal b/uxntal/fib.tal
new file mode 100644
index 0000000..9b5cb99
--- /dev/null
+++ b/uxntal/fib.tal
@@ -0,0 +1,22 @@
+( Fibonacci:
+	A series of numbers where the next number 
+	is made of the two numbers before it )
+
+|0100 ( -> ) @reset
+
+	#0000 INC2k ADD2k
+	&loop
+		( print ) DUP2 ,print JSR
+		( linebreak ) #0a18 DEO
+		ADD2k LTH2k ,&loop JCN
+	( halt ) #010f DEO
+
+BRK
+
+@print ( short* -- )
+
+	SWP ,&byte JSR
+	&byte ( byte -- ) DUP #04 SFT ,&char JSR
+	&char ( char -- ) #0f AND DUP #09 GTH #27 MUL ADD #30 ADD #18 DEO
+
+JMP2r
diff --git a/uxntal/hi.rom b/uxntal/hi.rom
deleted file mode 100644
index b3fd8ea..0000000
--- a/uxntal/hi.rom
+++ /dev/null
Binary files differdiff --git a/uxntal/primes.tal b/uxntal/primes.tal
new file mode 100644
index 0000000..3b9a7d9
--- /dev/null
+++ b/uxntal/primes.tal
@@ -0,0 +1,42 @@
+( Primes:
+	An integer greater than one is called a prime number
+	if its only positive divisors are one and itself. )
+
+|0100 ( -> ) @reset
+
+	#0000 INC2k
+	&loop
+		DUP2 ,is-prime JSR #00 EQU ,&skip JCN
+			( print ) DUP2 ,print/short JSR
+			( space ) #2018 DEO
+			&skip
+		INC2 NEQ2k ,&loop JCN
+	POP2 POP2
+	( halt ) #010f DEO
+	
+BRK
+
+@is-prime ( number* -- flag )
+
+	DUP2 #0001 EQU2 ,&fail JCN
+	STH2k
+	( range ) #01 SFT2 #0002
+	&loop
+		STH2kr OVR2 ( mod2 ) [ DIV2k MUL2 SUB2 ] ORA ,&continue JCN
+			POP2 POP2
+			POP2r #00 JMP2r
+			&continue
+		INC2 GTH2k ,&loop JCN
+	POP2 POP2
+	POP2r #01
+
+JMP2r
+	&fail POP2 #00 JMP2r
+
+@print ( short* -- )
+
+	&short ( short* -- ) SWP ,&byte JSR
+	&byte ( byte -- ) DUP #04 SFT ,&char JSR
+	&char ( char -- ) #0f AND DUP #09 GTH #27 MUL ADD #30 ADD #18 DEO
+
+JMP2r