aboutsummaryrefslogtreecommitdiff
path: root/forth/forth/avr/asm-examples.fs
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2018-09-29 01:02:00 +0200
committerDimitri Sokolyuk <demon@dim13.org>2018-09-29 01:02:00 +0200
commit79cabd5b1c8bcd9f50dc49e77776e713a57dff48 (patch)
tree6eb73857e9c174610839291cf05a02d77fc82b8c /forth/forth/avr/asm-examples.fs
parent247df3bb9d4c89d4e5ff18dcc23ba1c9532f28c0 (diff)
parent110a6411bae421260476eacf6173897c1d1f4b8a (diff)
Merge branch 'master' of dim13.org:elegoo
Diffstat (limited to 'forth/forth/avr/asm-examples.fs')
-rw-r--r--forth/forth/avr/asm-examples.fs36
1 files changed, 36 insertions, 0 deletions
diff --git a/forth/forth/avr/asm-examples.fs b/forth/forth/avr/asm-examples.fs
new file mode 100644
index 0000000..5765ee2
--- /dev/null
+++ b/forth/forth/avr/asm-examples.fs
@@ -0,0 +1,36 @@
+\ needs asm.txt
+
+-asmexamples
+marker -asmexamples
+
+\ Top of stack is always cached in R24:R25
+
+\ duplicate top of stack
+\ identical to DUP on FlashForth
+: _dup ( n -- n n )
+ [ R25 -Y st, ]
+ [ R24 -Y st, ]
+; inlined
+
+\ drop top of stack
+\ identical to DROP on FlashForth
+: _drop ( n -- )
+ [ R24 Y+ ld, ]
+ [ R25 Y+ ld, ]
+; inlined
+
+\ Load constant $1234 to top of stack
+: a-number ( -- 1234 )
+ dup \ Make space for new TOS value
+ [ R24 $34 ldi, ]
+ [ R25 $12 ldi, ]
+;
+
+\ Pop the top of stack to registers R18:R19
+\ R18 and R19 are free to use unless DO..LOOP is used
+: tos-to-r18-r19 ( n -- )
+ [ R18 R24 movw, ] \ Move TOS to R18:R19
+ drop \ load R24:R25 with new TOS
+;
+
+