@@ -7,13 +7,151 @@ Programming with Assembly
77
88
99
10- Arithmetic Program
11- ==================
10+ Revisiting Problems
11+ ===================
1212
13+ * Consider the problems already solved with machine code hex files
14+ * Instead of writing machine code, the assembler allows one to write in the assembly language
1315
16+ * The mnemonics can be used, making programming easier and making the program much easier to understand
1417
15- Counting Program
16- ================
18+
19+ * The assembly language is then assembled, with the assembler, to the machine code
20+ * This machine code can then be loaded into the ESAP system for execution
21+
22+
23+ Arithmetic
24+ ----------
25+
26+ * Consider the problem of outputting the result of the calculations ``31 + 32 `` and ``31 - 32 ``
27+
28+ * This problem was already discussed in the machine code topic
29+
30+
31+ .. list-table :: Arithmetic Program
32+ :header-rows: 1
33+ :align: center
34+
35+ * - Assembly
36+ - Machine Code
37+
38+ * - .. literalinclude:: arithmetic_31_32.esap
39+ :language: text
40+ :lineno-match:
41+
42+ - .. literalinclude:: arithmetic_31_32.hex
43+ :language: text
44+ :lineno-match:
45+
46+
47+ * Above is a table comparing the assembly language program and the corresponding machine code
48+
49+ * This machine code was generated by the assembler
50+ * The line numbers do not align here as the hex file requires the ``v2.0 raw `` line
51+
52+
53+ * Notice that the data (``31 `` and ``32 ``) is stored at the end of RAM
54+
55+ * This is not a requirement
56+ * Although the Von Neumann architecture has instructions and data share the same memory space
57+ * It is often desirable to try to physically separate instructions and data in some way
58+
59+ * May help with interpretability of programs
60+
61+
62+ * Also notice the ``NOOP ``\s filling the space between the instructions and data
63+
64+ * The assembler ignores white space, so any empty RAM addresses need to be explicitly set
65+
66+ * This was done here to facilitate physically separate instructions and data
67+
68+
69+ * Technically anything could be put in these addresses, data or instruction, as they follow ``HALT ``
70+
71+ * The system would never be able to run these RAM addresses
72+
73+
74+ * However, to make the program as clear and intentional as possible, ``NOOP ``\s were used
75+
76+ * Entering the data ``0x00 `` would also work, as it is the same bit pattern as ``NOOP ``
77+ * However, again, to make the assembly program more clear, ``NOOP `` is used
78+
79+
80+ * Finally, notice the use of hex values to specify addresses, but decimal for the data
81+
82+ * All values are in hex except ``31 `` and ``32 ``
83+ * This is not a requirement as the assembler converts everything to the same machine code, regardless of base
84+ * This decision was made here to help provide clarity to the program
85+
86+
87+ Counting
88+ --------
89+
90+ * Below is the program to count by ones forever
91+
92+ * Like the above arithmetic problem, this was already discussed in the machine code topic
93+
94+
95+ .. list-table :: Counting Forever Program
96+ :header-rows: 1
97+ :align: center
98+
99+ * - Assembly
100+ - Machine Code
101+
102+ * - .. literalinclude:: counting_forever.esap
103+ :language: text
104+ :lineno-match:
105+
106+ - .. literalinclude:: counting_forever.hex
107+ :language: text
108+ :lineno-match:
109+
110+
111+
112+ Check 10
113+ --------
114+
115+ * Below is the program to check if a number is ``< 10 ``
116+
117+ * This was discussed in the conditions and conditional jump topics
118+
119+
120+ .. list-table :: Check ``< 10`` Program
121+ :header-rows: 1
122+ :align: center
123+
124+ * - Assembly
125+ - Machine Code
126+
127+ * - .. literalinclude:: check_10.esap
128+ :language: text
129+ :lineno-match:
130+
131+ - .. literalinclude:: check_10.hex
132+ :language: text
133+ :lineno-match:
134+
135+
136+ * In the above program, like before, the value to check is stored in address ``0xF ``
137+
138+ * To check if a different value is less than 10, one would have to alter the code
139+
140+
141+ * Here, addresses ``0xD `` and ``0xE `` store the value to be output based on if the value is less than 10 or not
142+
143+ * Storing the value ``0 `` is not strictly necessary here for several reasons, but it does help with intentionality
144+
145+ * It's not needed because the ESAP system in Digital starts with a ``0 `` in the output register
146+ * Further, the ``NOOP ``\s are ``0 ``, so any of those addresses could be used
147+
148+
149+ * Again, ``NOOP ``\s are included to allow separation of the instructions and data
150+
151+
152+
153+ Count to 10
154+ ===========
17155
18156
19157
0 commit comments