Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions site/topics/programming/arithmetic_31_32.esap
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
LDAR 0xE
LDBR 0xF
ADAB
SAVA 0xD
OUTU 0xD
LDAR 0xE
SUAB
SAVA 0xD
OUTS 0xD
HALT
NOOP
NOOP
NOOP
NOOP
31
32
17 changes: 17 additions & 0 deletions site/topics/programming/arithmetic_31_32.hex
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
v2.0 raw
0x1e
0x3f
0x70
0x5d
0xdd
0x1e
0x80
0x5d
0xed
0xf0
0x00
0x00
0x00
0x00
0x1f
0x20
16 changes: 16 additions & 0 deletions site/topics/programming/check_10.esap
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
LDAR 0xF
LDBD 10
SUAB
JMPS 0x6
OUTU 0xD
HALT
OUTU 0xE
HALT
NOOP
NOOP
NOOP
NOOP
NOOP
0
1
5
17 changes: 17 additions & 0 deletions site/topics/programming/check_10.hex
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
v2.0 raw
0x1f
0x4a
0x80
0xb6
0xdd
0xf0
0xde
0xf0
0x00
0x00
0x00
0x00
0x00
0x00
0x01
0x0a
6 changes: 6 additions & 0 deletions site/topics/programming/counting_forever.esap
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
LDAD 0
LDBD 1
SAVA 0xF
OUTU 0xF
ADAB
JMPA 0x2
7 changes: 7 additions & 0 deletions site/topics/programming/counting_forever.hex
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
v2.0 raw
0x20
0x41
0x5f
0xdf
0x70
0x92
146 changes: 142 additions & 4 deletions site/topics/programming/programming-assembly.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,151 @@ Programming with Assembly



Arithmetic Program
==================
Revisiting Problems
===================

* Consider the problems already solved with machine code hex files
* Instead of writing machine code, the assembler allows one to write in the assembly language

* The mnemonics can be used, making programming easier and making the program much easier to understand

Counting Program
================

* The assembly language is then assembled, with the assembler, to the machine code
* This machine code can then be loaded into the ESAP system for execution


Arithmetic
----------

* Consider the problem of outputting the result of the calculations ``31 + 32`` and ``31 - 32``

* This problem was already discussed in the machine code topic


.. list-table:: Arithmetic Program
:header-rows: 1
:align: center

* - Assembly
- Machine Code

* - .. literalinclude:: arithmetic_31_32.esap
:language: text
:lineno-match:

- .. literalinclude:: arithmetic_31_32.hex
:language: text
:lineno-match:


* Above is a table comparing the assembly language program and the corresponding machine code

* This machine code was generated by the assembler
* The line numbers do not align here as the hex file requires the ``v2.0 raw`` line


* Notice that the data (``31`` and ``32``) is stored at the end of RAM

* This is not a requirement
* Although the Von Neumann architecture has instructions and data share the same memory space
* It is often desirable to try to physically separate instructions and data in some way

* May help with interpretability of programs


* Also notice the ``NOOP``\s filling the space between the instructions and data

* The assembler ignores white space, so any empty RAM addresses need to be explicitly set

* This was done here to facilitate physically separate instructions and data


* Technically anything could be put in these addresses, data or instruction, as they follow ``HALT``

* The system would never be able to run these RAM addresses


* However, to make the program as clear and intentional as possible, ``NOOP``\s were used

* Entering the data ``0x00`` would also work, as it is the same bit pattern as ``NOOP``
* However, again, to make the assembly program more clear, ``NOOP`` is used


* Finally, notice the use of hex values to specify addresses, but decimal for the data

* All values are in hex except ``31`` and ``32``
* This is not a requirement as the assembler converts everything to the same machine code, regardless of base
* This decision was made here to help provide clarity to the program


Counting
--------

* Below is the program to count by ones forever

* Like the above arithmetic problem, this was already discussed in the machine code topic


.. list-table:: Counting Forever Program
:header-rows: 1
:align: center

* - Assembly
- Machine Code

* - .. literalinclude:: counting_forever.esap
:language: text
:lineno-match:

- .. literalinclude:: counting_forever.hex
:language: text
:lineno-match:



Check 10
--------

* Below is the program to check if a number is ``< 10``

* This was discussed in the conditions and conditional jump topics


.. list-table:: Check ``< 10`` Program
:header-rows: 1
:align: center

* - Assembly
- Machine Code

* - .. literalinclude:: check_10.esap
:language: text
:lineno-match:

- .. literalinclude:: check_10.hex
:language: text
:lineno-match:


* In the above program, like before, the value to check is stored in address ``0xF``

* To check if a different value is less than 10, one would have to alter the code


* Here, addresses ``0xD`` and ``0xE`` store the value to be output based on if the value is less than 10 or not

* Storing the value ``0`` is not strictly necessary here for several reasons, but it does help with intentionality

* It's not needed because the ESAP system in Digital starts with a ``0`` in the output register
* Further, the ``NOOP``\s are ``0``, so any of those addresses could be used


* Again, ``NOOP``\s are included to allow separation of the instructions and data



Count to 10
===========
Comment on lines +153 to +154
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor, probably ditch the unused header

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added it to help make the next PR easier to merge




Expand Down