1 |
2 |
sinclairrf |
|
2 |
|
|
<!-- Copyright 2012, Sinclair R.F., Inc. -->
|
3 |
|
|
<html>
|
4 |
|
|
<title>
|
5 |
|
|
macros
|
6 |
|
|
</title>
|
7 |
|
|
<body>
|
8 |
|
|
<h1>Macros for the 9x8 micro controller</h1><br/>
|
9 |
|
|
Copyright 2012, Sinclair R.F., Inc.<br/><br/>
|
10 |
|
|
This document describes the macros for 9x8 micro controller.<br/><br/>
|
11 |
|
|
Macros are used to access opcodes that cannot be used directly or to help
|
12 |
|
|
improve code readability and provide syntax checking for some
|
13 |
|
|
opcodes.<br/><br/>
|
14 |
|
|
<h2>call, callc, jump, and jumpc</h2>
|
15 |
|
|
The unconditional and the conditional call and jump instructions are three
|
16 |
|
|
instruction sequences. The first instructions pushes the 8 lsb of
|
17 |
|
|
the target address onto the stack, the second instruction is the jump or
|
18 |
|
|
call with the 5 msb of the target address encoded into the
|
19 |
|
|
instruction, and the third instruction is the instruction that is always
|
20 |
|
|
executed immediately after the jump or call. Because the first two
|
21 |
|
|
instructions are dependent on the target address a macro is required to
|
22 |
|
|
generate the push and the call or jump instruction. Also, because the
|
23 |
|
|
instruction immediately after the call or jump is always executed
|
24 |
|
|
immediately after the call or jump it is also generated by the macro. The
|
25 |
|
|
default value for this third instruction can be changed by including it as
|
26 |
|
|
the optional second argument to the macro.<br/><br/>
|
27 |
|
|
<h2>fetch, fetch+, fetch-, store, store+, and store-</h2>
|
28 |
|
|
The fetch and store instructions required the 2 bit memory bank index
|
29 |
|
|
to be encoded as part of the fetch or store instruction. The memory bank
|
30 |
|
|
is specified by its name.<br/><br/>
|
31 |
|
|
The macros also ensure that the provided symbol is a memory bank
|
32 |
|
|
name.<br/><br/>
|
33 |
|
|
<h2>fetchvalue and storevalue</h2>
|
34 |
|
|
These macros are used read a value from or write a value to memory by
|
35 |
|
|
variable name. The offset of the variable within the memory bank is
|
36 |
|
|
pushed onto the data stack and the memory bank associated with the
|
37 |
|
|
variable is encoded into the <tt>fetch</tt> or <tt>store</tt> instruction.
|
38 |
|
|
The <tt>storevalue</tt> macro also consumes the top of the data stack by
|
39 |
|
|
adding a third, <tt>drop</tt> instruction.<br/><br/>
|
40 |
|
|
These macros ensure that the provided symbol is a variable name.<br/><br/>
|
41 |
|
|
<h2>fetchvector and storevector</h2>
|
42 |
|
|
These macros are used to generate multi-instructions sequences to transfer
|
43 |
|
|
two or more values between the memory and the data stack. The storevector
|
44 |
|
|
macro transfers the data stack to memory with the top of the data stack
|
45 |
|
|
stored at the specified variable, the next value stored at the next
|
46 |
|
|
location in memory and so forth. The fetchvector macro reads the values
|
47 |
|
|
from memory in the reverse order in which they were stored so that the
|
48 |
|
|
fetchvector and storevector macros are inverses of each other.<br/><br/>
|
49 |
|
|
If the MSB of a multi-byte value is stored at the top of the data stack as
|
50 |
|
|
per the Forth convention, then the storevector macro places the MSB at the
|
51 |
|
|
specified variable and the subsequent less significant bytes at subsequent
|
52 |
|
|
locations in memory.<br/><br/>
|
53 |
|
|
These macros ensure that the provided symbol is a variable name.<br/><br/>
|
54 |
|
|
<h2>fetchindexed and storeindex</h2>
|
55 |
|
|
If the top of the data stack is an index into a multi-byte value, these
|
56 |
|
|
macros can be used to fetch or store the associated value from the
|
57 |
|
|
specified variable. Using the macro ensures the correct memory bank is
|
58 |
|
|
used for the specified variable.<br/><br/>
|
59 |
|
|
These macros ensure that the provided symbol is a variable name.<br/><br/>
|
60 |
|
|
<h2>inport and outport</h2>
|
61 |
|
|
The <tt>inport</tt> and <tt>outport</tt> instructions can be specified
|
62 |
|
|
directly in the assembly file. However, the code reliability and
|
63 |
|
|
readability can be improved by using the macros. For example, if the top
|
64 |
|
|
of the data stack is to be output to the specified port and then dropped,
|
65 |
|
|
the macro <tt>.outport(O_NAME)</tt> will generate the required three
|
66 |
|
|
instruction sequence.<br/><br/>
|
67 |
|
|
These macros also ensure that and input port or an output port respectively
|
68 |
|
|
are specified to the macro, thus helping to identify coding
|
69 |
|
|
mistakes.<br/><br/>
|
70 |
|
|
<h2>return</h2>
|
71 |
|
|
Because the instruction immediately following the return instruction is
|
72 |
|
|
executed immediately after the return instruction, a macro is used to
|
73 |
|
|
ensure that the two instruction sequence is properly generated. The
|
74 |
|
|
default instruction can be changed by providing the optional argument to
|
75 |
|
|
the macro.<br/><br/>
|
76 |
|
|
<h1>Macros</h1>
|
77 |
|
|
Alphebetic listing:
|
78 |
|
|
<a href="#.call">.call</a>,
|
79 |
|
|
<a href="#.callc">.callc</a>,
|
80 |
|
|
<a href="#.fetch">.fetch</a>,
|
81 |
|
|
<a href="#.fetch+">.fetch+</a>,
|
82 |
|
|
<a href="#.fetch-">.fetch-</a>,
|
83 |
|
|
<a href="#.fetchindexed">.fetchindexed</a>,
|
84 |
|
|
<a href="#.fetchvalue">.fetchvalue</a>,
|
85 |
|
|
<a href="#.fetchvector">.fetchvector</a>,
|
86 |
|
|
<a href="#.inport">.inport</a>,
|
87 |
|
|
<a href="#.jump">.jump</a>,
|
88 |
|
|
<a href="#.jumpc">.jumpc</a>,
|
89 |
|
|
<a href="#.outport">.outport</a>,
|
90 |
|
|
<a href="#.return">.return</a>,
|
91 |
|
|
<a href="#.store">.store</a>,
|
92 |
|
|
<a href="#.store+">.store+</a>,
|
93 |
|
|
<a href="#.store-">.store-</a>,
|
94 |
|
|
<a href="#.storeindexed">.storeindexed</a>,
|
95 |
|
|
<a href="#.storevalue">.storevalue</a>,
|
96 |
|
|
and <a href="#.storevector">.storevector</a>.<br/><br/>
|
97 |
|
|
<h2><a name=".call">.call</a></h2>
|
98 |
|
|
<b>Description:</b> Generate the 3 instruction sequence associated with a <tt>call</tt> instruction.<br/><br/>
|
99 |
|
|
<b>Operation(1):</b> <tt>.call(label)</tt> generates the following 3 instructions:<br/>
|
100 |
|
|
1 — push the 8 lsb of the label address onto the data stack<br/>
|
101 |
|
|
2 — call with the 5 msb of the label address encoded in the call instruction<br/>
|
102 |
|
|
3 — no operation<br/><br/>
|
103 |
|
|
<b>Operation(2):</b> <tt>.call(label,op)</tt> where "op" is an instruction generates the following 3 instructions:<br/>
|
104 |
|
|
1 — push the 8 lsb of the label address onto the data stack<br/>
|
105 |
|
|
2 — call with the 5 msb of the label address encoded in the call instruction<br/>
|
106 |
|
|
3 — op<br/><br/>
|
107 |
|
|
Note that Operation(1) is a special case of Operation(2) with "op" being the <tt>nop</tt> instruction.<br/>
|
108 |
|
|
<h2><a name=".callc">.callc</a></h2>
|
109 |
|
|
<b>Description:</b> Generate the 3 instruction sequence associated with a <tt>callc</tt> instruction.<br/><br/>
|
110 |
|
|
<b>Operation(1):</b> <tt>.callc(label)</tt> generates the following 3 instructions:<br/>
|
111 |
|
|
1 — push the 8 lsb of the label address onto the data stack<br/>
|
112 |
|
|
2 — callc with the 5 msb of the label address encoded in the callc instruction<br/>
|
113 |
|
|
3 — drop<br/><br/>
|
114 |
|
|
<b>Operation(2):</b> <tt>.callc(label,op)</tt> where "op" is an instruction generates the following 3 instructions:<br/>
|
115 |
|
|
1 — push the 8 lsb of the label address onto the data stack<br/>
|
116 |
|
|
2 — callc with the 5 msb of the label address encoded in the callc instruction<br/>
|
117 |
|
|
3 — op<br/><br/>
|
118 |
|
|
Note that Operation(1) is a special case of Operation(2) with "op" being the <tt>drop</tt> instruction.<br/>
|
119 |
|
|
<h2><a name=".fetch">.fetch</a></h2>
|
120 |
|
|
<b>Description:</b> Generate the <tt>fetch</tt> instruction.<br/><br/>
|
121 |
|
|
<b>Operation:</b> <tt>.fetch(ram)</tt> generates the following instruction:<br/>
|
122 |
|
|
1 — fetch with the 2 bit memory index encoded in the fetch instruction.<br/>
|
123 |
|
|
<h2><a name=".fetch+">.fetch+</a></h2>
|
124 |
|
|
<b>Description:</b> Generate the <tt>fetch+</tt> instruction.<br/><br/>
|
125 |
|
|
<b>Operation:</b> <tt>.fetch+(ram)</tt> generates the following instruction:<br/>
|
126 |
|
|
1 — fetch+ with the 2 bit memory index encoded in the fetch+ instruction.<br/>
|
127 |
|
|
<h2><a name=".fetch-">.fetch-</a></h2>
|
128 |
|
|
<b>Description:</b> Generate the <tt>fetch-</tt> instruction.<br/><br/>
|
129 |
|
|
<b>Operation:</b> <tt>.fetch-(ram)</tt> generates the following instruction:<br/>
|
130 |
|
|
1 — fetch- with the 2 bit memory index encoded in the fetch- instruction.<br/>
|
131 |
|
|
<h2><a name=".fetchindexed">.fetchindexed</a></h2>
|
132 |
|
|
TODO
|
133 |
|
|
<h2><a name=".fetchvalue">.fetchvalue</a></h2>
|
134 |
|
|
TODO
|
135 |
|
|
<h2><a name=".fetchvector">.fetchvector</a></h2>
|
136 |
|
|
TODO
|
137 |
|
|
<h2><a name=".inport">.inport</a></h2>
|
138 |
|
|
<b>Description:</b> Generate the 2 instruction sequence associated with a <tt>inport</tt> instruction.<br/><br/>
|
139 |
|
|
<b>Operation:</b> <tt>.inport(label)</tt> generates the following 3 instructions:<br/>
|
140 |
|
|
1 — push the 8 lsb of the label address onto the data stack<br/>
|
141 |
|
|
2 — <tt>inport</tt><br/>
|
142 |
|
|
<h2>.jump</h2>
|
143 |
|
|
<b>Description:</b> Generate the 3 instruction sequence associated with a <tt>jump</tt> instruction.<br/><br/>
|
144 |
|
|
<b>Operation(1):</b> <tt>.jump(label)</tt> generates the following 3 instructions:<br/>
|
145 |
|
|
1 — push the 8 lsb of the label address onto the data stack<br/>
|
146 |
|
|
2 — jump with the 5 msb of the label address encoded in the jump instruction<br/>
|
147 |
|
|
3 — no operation<br/><br/>
|
148 |
|
|
<b>Operation(2):</b> <tt>.jump(label,op)</tt> where "op" is an instruction generates the following 3 instructions:<br/>
|
149 |
|
|
1 — push the 8 lsb of the label address onto the data stack<br/>
|
150 |
|
|
2 — jump with the 5 msb of the label address encoded in the jump instruction<br/>
|
151 |
|
|
3 — op<br/><br/>
|
152 |
|
|
Note that Operation(1) is a special case of Operation(2) with "op" being the <tt>nop</tt> instruction.<br/>
|
153 |
|
|
<h2>.jumpc</h2>
|
154 |
|
|
<b>Description:</b> Generate the 3 instruction sequence associated with a <tt>jumpc</tt> instruction.<br/><br/>
|
155 |
|
|
<b>Operation(1):</b> <tt>.jumpc(label)</tt> generates the following 3 instructions:<br/>
|
156 |
|
|
1 — push the 8 lsb of the label address onto the data stack<br/>
|
157 |
|
|
2 — jumpc with the 5 msb of the label address encoded in the jumpc instruction<br/>
|
158 |
|
|
3 — drop<br/><br/>
|
159 |
|
|
<b>Operation(2):</b> <tt>.jumpc(label,op)</tt> where "op" is an instruction generates the following 3 instructions:<br/>
|
160 |
|
|
1 — push the 8 lsb of the label address onto the data stack<br/>
|
161 |
|
|
2 — jumpc with the 5 msb of the label address encoded in the jumpc instruction<br/>
|
162 |
|
|
3 — op<br/><br/>
|
163 |
|
|
Note that Operation(1) is a special case of Operation(2) with "op" being the <tt>drop</tt> instruction.<br/>
|
164 |
|
|
<h2><a name=".outport">.outport</a></h2>
|
165 |
|
|
<b>Description:</b> Generate the 3 instruction sequence associated with a <tt>outport</tt> instruction.<br/><br/>
|
166 |
|
|
<b>Operation(1):</b> <tt>.outport(label)</tt> generates the following 3 instructions:<br/>
|
167 |
|
|
1 — push the 8 lsb of the label address onto the data stack<br/>
|
168 |
|
|
2 — <tt>outport</tt><br/>
|
169 |
|
|
3 — <tt>drop</tt><br/><br/>
|
170 |
|
|
<b>Operation(2):</b> <tt>.outport(label,op)</tt> generates the following 3 instructions:<br/>
|
171 |
|
|
1 — push the 8 lsb of the label address onto the data stack<br/>
|
172 |
|
|
2 — <tt>outport</tt><br/>
|
173 |
|
|
3 — op<br/><br/>
|
174 |
|
|
Note that Operation(1) is a special case of Operation(2) with "op" being the <tt>drop</tt> instruction.<br/>
|
175 |
|
|
<h2><a name=".return">.return</a></h2>
|
176 |
|
|
TODO
|
177 |
|
|
<h2><a name=".store">.store</a></h2>
|
178 |
|
|
<b>Description:</b> Generate the <tt>store</tt> instruction.<br/><br/>
|
179 |
|
|
<b>Operation:</b> <tt>.store(ram)</tt> generates the following instruction:<br/>
|
180 |
|
|
1 — store with the 2 bit memory index encoded in the store instruction.<br/>
|
181 |
|
|
<h2><a name=".store+">.store+</a></h2>
|
182 |
|
|
<b>Description:</b> Generate the <tt>store+</tt> instruction.<br/><br/>
|
183 |
|
|
<b>Operation:</b> <tt>.store+(ram)</tt> generates the following instruction:<br/>
|
184 |
|
|
1 — store+ with the 2 bit memory index encoded in the store+ instruction.<br/>
|
185 |
|
|
<h2><a name=".store-">.store-</a></h2>
|
186 |
|
|
<b>Description:</b> Generate the <tt>store-</tt> instruction.<br/><br/>
|
187 |
|
|
<b>Operation:</b> <tt>.store-(ram)</tt> generates the following instruction:<br/>
|
188 |
|
|
1 — store- with the 2 bit memory index encoded in the store- instruction.<br/>
|
189 |
|
|
<h2><a name=".storeindexed">.storeindexed</a></h2>
|
190 |
|
|
TODO
|
191 |
|
|
<h2><a name=".storevalue">.storevalue</a></h2>
|
192 |
|
|
TODO
|
193 |
|
|
<h2><a name=".storevector">.storevector</a></h2>
|
194 |
|
|
TODO
|
195 |
|
|
</body>
|
196 |
|
|
</html>
|