Skip to content

Commit f9d5635

Browse files
🎓 Topic assembly programming --- Revisit problems (#227)
1 parent 78b2ca5 commit f9d5635

File tree

7 files changed

+221
-4
lines changed

7 files changed

+221
-4
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
LDAR 0xE
2+
LDBR 0xF
3+
ADAB
4+
SAVA 0xD
5+
OUTU 0xD
6+
LDAR 0xE
7+
SUAB
8+
SAVA 0xD
9+
OUTS 0xD
10+
HALT
11+
NOOP
12+
NOOP
13+
NOOP
14+
NOOP
15+
31
16+
32
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
v2.0 raw
2+
0x1e
3+
0x3f
4+
0x70
5+
0x5d
6+
0xdd
7+
0x1e
8+
0x80
9+
0x5d
10+
0xed
11+
0xf0
12+
0x00
13+
0x00
14+
0x00
15+
0x00
16+
0x1f
17+
0x20
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
LDAR 0xF
2+
LDBD 10
3+
SUAB
4+
JMPS 0x6
5+
OUTU 0xD
6+
HALT
7+
OUTU 0xE
8+
HALT
9+
NOOP
10+
NOOP
11+
NOOP
12+
NOOP
13+
NOOP
14+
0
15+
1
16+
5
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
v2.0 raw
2+
0x1f
3+
0x4a
4+
0x80
5+
0xb6
6+
0xdd
7+
0xf0
8+
0xde
9+
0xf0
10+
0x00
11+
0x00
12+
0x00
13+
0x00
14+
0x00
15+
0x00
16+
0x01
17+
0x0a
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
LDAD 0
2+
LDBD 1
3+
SAVA 0xF
4+
OUTU 0xF
5+
ADAB
6+
JMPA 0x2
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
v2.0 raw
2+
0x20
3+
0x41
4+
0x5f
5+
0xdf
6+
0x70
7+
0x92

‎site/topics/programming/programming-assembly.rst‎

Lines changed: 142 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)