13 |
14 | MicroMini:
15 | A Racket-powered 8-bit stack machine
16 |
17 |
18 | John S. Berry III
19 |
20 |
21 | Last updated 11.08.2014
22 |
23 |
24 | 1 Introduction
25 |
26 |
27 | The MicroMini is a virtual stack machine inspired by classic minicomputers. It is written in Racket, an excellent Scheme-derived Lisp with a specialty in teaching and new language development. MicroMini is purely stack based: other than memory calls, almost all operations take no arguments, collecting their required operands from the top of the stack.
28 |
29 |
30 | 1.1 Specifications
31 |
32 |
33 | The MicroMini is patterned after an imaginary vintage minicomputer, scaled down to home-size. As such, it’s basic specifications are thus kept within those limits, save that at present, the device runs at the full speed of the user’s computer rather than an artificially limited operation speed.
34 |
35 |
36 | -
37 | 8-bit data bus
38 |
39 | -
40 | 16-bit address bus
41 |
42 | -
43 | 64Kib of RAM
44 |
45 | -
46 | 16-bit pointer-based stack
47 |
48 | -
49 | 16-bit program and return pointers
50 |
51 | -
52 | 1-bit halt flag
53 |
54 | -
55 | 1-bit carry flag
56 |
57 | -
58 | 8-bit cycle counter
59 |
60 |
61 |
62 |
63 | 1.2 Usage and Requirements
64 |
65 |
66 | At this time, MicroMini only runs on Unix-derived operating systems which provide stty. Future implementations may correct this, however as it stands, there are no Racket libs for Windows platforms which can correctly handle the TRMI and TRMO instructions.
67 |
68 |
69 | If running the binary, you need only invoke it from the command line, like so:
70 |
71 |
72 |
73 |
mmini <mm-binary-file>
74 |
75 |
76 |
77 |
78 |
79 | Where mm-binary-file is the filename of a previously created binary file composed of 8-bit bytes of MicroMini machine code. Currently there is no compiler or assembler available for MicroMini, but the author intends to create one soon.
80 |
81 |
82 | If you wish to run MicroMini from the source, you will need to install Racket. The program was created with Racket 6.1, and the author can make no guarantees about backwards compatibility. To install and invoke it, you can do:
83 |
84 |
85 |
86 |
> git clone https://github.com/jarcane/MicroMini.git
87 | > cd ./MicroMini
88 | > racket main.rkt <mm-binary-file>
89 |
90 |
91 |
92 |
93 |
94 | Where, as before, mm-binary-file is a previously created MM binary.
95 |
96 |
97 | 2 MicroMini Operation
98 |
99 |
100 | On invocation, MicroMini will take the target file, read it byte by byte into memory, and begin executing from address #x0000. It will continue to run through valid instructions until it reaches the end of the RAM bank, it is given a HLT instruction, or there is an error. I/O at this point comes purely via terminal, handled via the TRMI and TRMO instructions.
101 |
102 |
103 | Each cycle, the MicroMini:
104 |
105 |
106 | -
107 | Executes the instruction found at the address designated by the program counter
108 |
109 | -
110 | Increments the program pointer by 1
111 |
112 | -
113 | Checks if the program pointer has reached the end of ram space and, if so, sets the halt-bit
114 |
115 | -
116 | Checks the cycle counter:
117 | -
118 | If full, resets to 0
119 |
120 | -
121 | If not, increments by 1
122 |
123 |
124 |
125 |
126 |
127 | -
128 | Checks the halt-bit, and stops execution if set
129 |
130 |
131 |
132 |
133 | 3 MicroMini Instructions
134 |
135 |
136 | The following are the standard instructions currently implemented in MicroMini, with descriptions of their operation.
137 |
138 |
139 | 3.1 #x00 NOP - No OPeration
140 |
141 |
142 | Does nothing, and will be skipped by the processor.
143 |
144 |
145 | 3.2 #x01 HLT - HaLT
146 |
147 |
148 | Sets the halt-bit on the processor, which will cause it to end operation at the end of the cycle.
149 |
150 |
151 | 3.3 #x02 DATA num
152 |
153 |
154 | Consumes the next byte, and increments the program pointer by num spaces, essentially skipping over that many bytes in RAM.
155 |
156 |
157 | 3.4 #x10 ADD
158 |
159 |
160 | Pops the top two values in the stack, adds them, and pushes the result to the stack. If there has been an overflow, the carry-bit is set.
161 |
162 |
163 | 3.5 #x20 SUB
164 |
165 |
166 | Pops the top two values in the stack, subtracts the top value from the one below it, and pushes the result to the stack. If there is an underflow, the carry-bit is set.
167 |
168 |
169 | 3.6 #x30 AND
170 |
171 |
172 | Pops the top two values in the stack, ANDs their bits, and pushes the result to the stack.
173 |
174 |
175 | 3.7 #x31 OR
176 |
177 |
178 | Pops the top two values in the stack, ORs their bits, and pushes the result to the stack.
179 |
180 |
181 | 3.8 #x32 XOR
182 |
183 |
184 | Pops the top two values in the stack, XORs their bits, and pushes the result to the stack.
185 |
186 |
187 | 3.9 #x33 NOT
188 |
189 |
190 | Pops the top value from the stack, applies NOT, and pushes the result to the stack.
191 |
192 |
193 | 3.10 #x40 EQ? - EQual?
194 |
195 |
196 | Pops the top two values from the stack, and compares them. If they are equal, pushes 0x01 to the stack. If not equal, pushes 0x00.
197 |
198 |
199 | 3.11 #x41 LES? - LESser?
200 |
201 |
202 | Pops the top two values from the stack, and compares the top value to the one below it. If the top value is lesser, pushes 0x01 to the stack. If the top value is greater, pushes 0x00 to the stack.
203 |
204 |
205 | 3.12 #x42 GRT? - GReaTer?
206 |
207 |
208 | Pops the top two values from the stack, and compares the top value to the one below it. If the top value is greater, pushes 0x01 to the stack. If the top value is lesser, pushes 0x00 to the stack.
209 |
210 |
211 | 3.13 #x50 PUSH num
212 |
213 |
214 | Consumes the next byte of ram, and pushes the value to the stack.
215 |
216 |
217 | 3.14 #x51 PUFA address - PUsh From Address
218 |
219 |
220 | Consumes the next two bytes as an address location, and pushes the value at that address to the stack.
221 |
222 |
223 | 3.15 #x52 PUCA - PUsh CArry
224 |
225 |
226 | Pushes the current carry flag to the stack.
227 |
228 |
229 | 3.16 #x53 PUTI - PUsh TImer
230 |
231 |
232 | Pushes the current value of the cycle counter to the stack.
233 |
234 |
235 | 3.17 #x60 POP
236 |
237 |
238 | Consumes the top value from the stack.
239 |
240 |
241 | 3.18 #x61 POTA address - POp To Address
242 |
243 |
244 | Consumes the next two bytes as an address location, pops the value from the top of the stack, and stores at at that address.
245 |
246 |
247 | 3.19 #x70 JMP address - JuMP
248 |
249 |
250 | Consumes the next two bytes as an address location, and sets the program pointer to continue execution from that address on the next cycle.
251 |
252 |
253 | 3.20 #x71 JSR address - Jump to SubRoutine
254 |
255 |
256 | Stores the current program pointer (skipping itself) to the return pointer, consumes the next two bytes as an address location, then sets the program pointer to continue execution at that address on the next cycle. Note that the return pointer does not actually point to the original location, but rather the location just past the original JSR instruction and its address, in order to prevent unbreakable loops.
257 |
258 |
259 | 3.21 #x72 JIF address - Jump IF
260 |
261 |
262 | Pops the top value of the stack. If it is 0x01, it consumes the next two bytes as an address, then sets the program pointer to continue execution from that address on the next cycle. Otherwise, it skips the next two bytes (to avoid attempting to execute the address values), but otherwise does nothing.
263 |
264 |
265 | 3.22 #x73 RET - Return
266 |
267 |
268 | Sets the program pointer equal to the return pointer, thus causing the CPU to resume execution just past the original JSR on the next cycle.
269 |
270 |
271 | 3.23 #x80 TRMI - TeRMinal Input
272 |
273 |
274 | Waits for the terminal to send a byte of input, then pushes that byte to the stack.
275 |
276 |
277 | 3.24 #x90 TRMO
278 |
279 |
280 | Pops the top value of the stack, and sends the byte to the terminal as output.
281 |
282 |
283 |
284 |
287 |
288 |
289 |
290 |
--------------------------------------------------------------------------------
/docs/MicroMini.lyx:
--------------------------------------------------------------------------------
1 | #LyX 2.0 created this file. For more info see http://www.lyx.org/
2 | \lyxformat 413
3 | \begin_document
4 | \begin_header
5 | \textclass article
6 | \use_default_options true
7 | \maintain_unincluded_children false
8 | \language english
9 | \language_package default
10 | \inputencoding auto
11 | \fontencoding global
12 | \font_roman default
13 | \font_sans default
14 | \font_typewriter default
15 | \font_default_family default
16 | \use_non_tex_fonts false
17 | \font_sc false
18 | \font_osf false
19 | \font_sf_scale 100
20 | \font_tt_scale 100
21 |
22 | \graphics default
23 | \default_output_format default
24 | \output_sync 0
25 | \bibtex_command default
26 | \index_command default
27 | \paperfontsize default
28 | \use_hyperref false
29 | \papersize default
30 | \use_geometry false
31 | \use_amsmath 1
32 | \use_esint 1
33 | \use_mhchem 1
34 | \use_mathdots 1
35 | \cite_engine basic
36 | \use_bibtopic false
37 | \use_indices false
38 | \paperorientation portrait
39 | \suppress_date false
40 | \use_refstyle 1
41 | \index Index
42 | \shortcut idx
43 | \color #008000
44 | \end_index
45 | \secnumdepth 3
46 | \tocdepth 3
47 | \paragraph_separation indent
48 | \paragraph_indentation default
49 | \quotes_language english
50 | \papercolumns 1
51 | \papersides 1
52 | \paperpagestyle default
53 | \tracking_changes false
54 | \output_changes false
55 | \html_math_output 0
56 | \html_css_as_file 0
57 | \html_be_strict false
58 | \end_header
59 |
60 | \begin_body
61 |
62 | \begin_layout Title
63 | MicroMini:
64 | \begin_inset Newline newline
65 | \end_inset
66 |
67 | A Racket-powered 8-bit stack machine
68 | \end_layout
69 |
70 | \begin_layout Author
71 | John S.
72 | Berry III
73 | \end_layout
74 |
75 | \begin_layout Date
76 | Last updated 11.08.2014
77 | \end_layout
78 |
79 | \begin_layout Section
80 | Introduction
81 | \end_layout
82 |
83 | \begin_layout Standard
84 | The MicroMini is a virtual stack machine inspired by classic minicomputers.
85 | It is written in Racket, an excellent Scheme-derived Lisp with a specialty
86 | in teaching and new language development.
87 | MicroMini is purely stack based: other than memory calls, almost all operations
88 | take no arguments, collecting their required operands from the top of the
89 | stack.
90 |
91 | \end_layout
92 |
93 | \begin_layout Subsection
94 | Specifications
95 | \end_layout
96 |
97 | \begin_layout Standard
98 | The MicroMini is patterned after an imaginary vintage minicomputer, scaled
99 | down to home-size.
100 | As such, it's basic specifications are thus kept within those limits, save
101 | that at present, the device runs at the full speed of the user's computer
102 | rather than an artificially limited operation speed.
103 | \end_layout
104 |
105 | \begin_layout Itemize
106 | 8-bit data bus
107 | \end_layout
108 |
109 | \begin_layout Itemize
110 | 16-bit address bus
111 | \end_layout
112 |
113 | \begin_layout Itemize
114 | 64Kib of RAM
115 | \end_layout
116 |
117 | \begin_layout Itemize
118 | 16-bit pointer-based stack
119 | \end_layout
120 |
121 | \begin_layout Itemize
122 | 16-bit program and return pointers
123 | \end_layout
124 |
125 | \begin_layout Itemize
126 | 1-bit halt flag
127 | \end_layout
128 |
129 | \begin_layout Itemize
130 | 1-bit carry flag
131 | \end_layout
132 |
133 | \begin_layout Itemize
134 | 8-bit cycle counter
135 | \end_layout
136 |
137 | \begin_layout Subsection
138 | Usage and Requirements
139 | \end_layout
140 |
141 | \begin_layout Standard
142 | At this time, MicroMini only runs on Unix-derived operating systems which
143 | provide
144 | \emph on
145 | stty.
146 |
147 | \emph default
148 | Future implementations may correct this, however as it stands, there are
149 | no Racket libs for Windows platforms which can correctly handle the TRMI
150 | and TRMO instructions.
151 | \end_layout
152 |
153 | \begin_layout Standard
154 | If running the binary, you need only invoke it from the command line, like
155 | so:
156 | \end_layout
157 |
158 | \begin_layout Standard
159 | \begin_inset listings
160 | inline false
161 | status open
162 |
163 | \begin_layout Plain Layout
164 |
165 | mmini