aboutsummaryrefslogtreecommitdiff
path: root/forth/forth/avr/asm-examples.fs
blob: 5765ee2e82cc789c9fda29179cfd40583d9c784d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
;