@@ -155,6 +155,69 @@ Count to 10
155155
156156
157157
158+ Count to 10
159+ ===========
160+
161+ * With the use of the assembler, the programs are easier to write and understand
162+ * This is important as solving complex problems is challenging enough as is
163+
164+ * The tedium of machine code only makes solving complex problems that much more difficult
165+
166+
167+ * Consider the more complex problem of counting to 10
168+
169+ * Output the numbers ``1 `` to ``10 ``
170+ * This may sound simple, but it is challenging when programming at such a low level
171+
172+
173+ * This problem combines two of the previous problems
174+
175+ * Counting forever
176+
177+ * requires looping
178+
179+
180+ * Checking if a value is less than 10
181+
182+ * requires branching
183+
184+
185+ * Below is the assembly and corresponding machine code for a solution to this problem
186+
187+ .. list-table :: Count to 10
188+ :header-rows: 1
189+ :align: center
190+
191+ * - Assembly
192+ - Machine Code
193+
194+ * - .. literalinclude:: counting_10.esap
195+ :language: text
196+ :lineno-match:
197+
198+ - .. literalinclude:: counting_10.hex
199+ :language: text
200+ :lineno-match:
201+
202+
203+ * Notice how the count value must be preserved before the subtraction can happen
204+ * Here, the ``JMPS `` instruction is used like a kind of while loop
205+
206+ * While the count is less than 10, jump
207+
208+
209+ * Note that, when running the program, it will appear to count ``0 `` -- ``10 ``
210+
211+ * This is due to the simulator and how the output register starts with a ``0 ``
212+
213+
214+ * Additionally, the starting instructions of ``LDAD 0 `` and ``SAVA 0xF `` could have been excluded
215+
216+ * The simulator initializes RAM with ``0 ``\s
217+ * However, having clear and intentional code is preferred
218+
219+
220+
158221For Next Time
159222=============
160223
0 commit comments