-
Notifications
You must be signed in to change notification settings - Fork 0
/
tovalue.asm
138 lines (127 loc) · 4.06 KB
/
tovalue.asm
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
; ====================================================================
; Experimental VALUE/TO code for CamelForth/8052 (internal RAM)
; (c) 2000 Bradford J. Rodriguez
; Permission is granted to freely copy, modify, and distribute this
; program for personal or educational use. Commercial inquiries should
; be directed to the author at 115 First St., #105, Collingwood, Ontario
; L9Y 4W3 Canada
; ====================================================================
; REVISION HISTORY
; $Log: Tovalue.asm,v $
;
; 7 Nov 2000 - initial (alpha test) version.
; ====================================================================
; DESCRIPTION
;
; This code does "run time" binding using the 8051 user flags
; PSW.5 and PSW.1. These flags are otherwised unused by CamelForth.
; They must be left undisturbed by the application!
;
; PSW.5 PSW.1 VALUE action
; 0 0 fetch
; 0 1 RAM address
; 1 0 store
; 1 1 plusstore
;
; This is slightly slower than a "compile time" binding approach,
; but much simpler.
;X TO -- store data in VALUE which follows
.drw link
.link
.fw TO
TO: setb psw.5
ret
;Z +TO -- add data to VALUE which follows
.drw link
.link
.fw +TO
PLUSTO: setb psw.5
setb psw.1
ret
;Z ADR -- get address of VALUE which follows
.drw link
.link
.fw ADR
ADR: setb psw.1
ret
; Usage:
; VALUE FOO defines a RAM value named FOO
; FOO returns contents of FOO
; n TO FOO stores n in FOO
; n +TO FOO adds n to FOO
; ADR FOO returns address of FOO
; --------------------------------------------------------------------
; CELL values
;X VALUE -- define cell VALUE variable
; <BUILDS HERE I, Harvard model, 8052
; CELL ALLOT
; DOES> (machine code fragment)
.drw link
.link
.fw VALUE
VALUE: lcall BUILDS
lcall HERE
lcall ICOMMA
lcall CELL
lcall ALLOT
lcall XDOES
; DOVALUE, code action of VALUE,
; entered by CALL DOVALUE
dovalue: ; -- x exec action of VALUE
dec r0 ; push old TOS
mov @r0,dph
dec r0
mov @r0,dpl
pop dph ; get addr of param field
pop dpl ; (in Code memory!)
lcall IFETCH ; fetch ROM contents (RAM address)
; Now we have ( oldTOS RAMadr ) on stack.
; Do the desired action.
; Note that this leaves psw.1 and psw.5 cleared.
jbc psw.1,adrvalue
jbc psw.5,tovalue
ljmp FETCH ; fetch RAM contents
adrvalue: jbc psw.5,plusvalue
ret ; return RAM address
tovalue: ljmp STORE ; store to RAM
plusvalue: ljmp PLUSSTORE ; add to RAM
; defined VALUE words are compiled as:
; <forth header>
; LCALL dovalue
; DRW ram-address
; --------------------------------------------------------------------
; BYTE values
;Z CVALUE -- define cell VALUE variable
; <BUILDS HERE I, Harvard model, 8052
; 1 CHARS ALLOT
; DOES> (machine code fragment)
.drw link
.link
.fw CVALUE
CVALUE: lcall BUILDS
lcall HERE
lcall ICOMMA
lcall LIT
.drw 1
lcall ALLOT
lcall XDOES
; DOCVALUE, code action of CVALUE,
; entered by CALL DOCVALUE
docvalue: ; -- x exec action of CVALUE
dec r0 ; push old TOS
mov @r0,dph
dec r0
mov @r0,dpl
pop dph ; get addr of param field
pop dpl ; (in Code memory!)
lcall IFETCH ; fetch ROM contents (RAM address)
; Now we have ( oldTOS RAMadr ) on stack.
; Do the desired action.
; Note that this leaves psw.1 and psw.5 cleared.
jbc psw.1,adrcvalue
jbc psw.5,tocvalue
ljmp CFETCH ; fetch RAM contents
adrcvalue: jbc psw.5,pluscvalue
ret ; return RAM address
tocvalue: ljmp CSTORE ; store to RAM
pluscvalue: ljmp CPLUSSTORE ; add to RAM