Skip to content

Commit

Permalink
Merge pull request #71 from ninezerozeronine/add_arith_instrs
Browse files Browse the repository at this point in the history
Add arith instrs
  • Loading branch information
ninezerozeronine committed Nov 12, 2019
2 parents fab8be7 + a030adf commit 6c1197c
Show file tree
Hide file tree
Showing 30 changed files with 1,826 additions and 13 deletions.
75 changes: 71 additions & 4 deletions docs/language/assembly.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,20 @@ The possible usages are:
- ``ADD C``
- ``ADD CONST``


ADDC
^^^^

The ``ADDC`` operation adds the value held in the specified module (or a
constant) to the accumulator. If the carry flag is high, an additional 1 is
added. The ALU flags generated by this operation are stored.

The possible usages are:

- ``ADDC A``
- ``ADDC B``
- ``ADDC C``
- ``ADDC CONST``

SUB
^^^

Expand All @@ -49,18 +59,75 @@ The possible usages are:
SUBB
^^^^

The ``SUBB`` operation subtracts the value held in the specified module (or a
constant) from the accumulator. If the borrow flag is high an additional 1 is
subtracted. The ALU flags generated by this operation are
stored.

The possible usages are:

- ``SUBB A``
- ``SUBB B``
- ``SUBB C``
- ``SUBB CONST``

LSHIFT
^^^^^^

The ``LSHIFT`` operation moves all the bits in the specified module one place
to the left (toward the most significant bit) in place. A zero is added in the
rightmost (least significant bit) place. The ALU flags generated by this
operation are stored.

The possible usages are:

- ``LSHIFT ACC``
- ``LSHIFT A``
- ``LSHIFT B``
- ``LSHIFT C``

LSHIFTC
^^^^^^^

The ``LSHIFTC`` operation moves all the bits in the specified module one place
to the left (toward the most significant bit) in place. If the carry flag is
high, a 1 is added in the rightmost (least significant bit) place. If the
flag is low, the rightmost place is left as 0. The ALU flags generated by this
operation are stored.

The possible usages are:

- ``LSHIFT ACC``
- ``LSHIFT A``
- ``LSHIFT B``
- ``LSHIFT C``

INCR
^^^^

The ``INCR`` operation adds one to the given argument (in place). The ALU flags
generated by this operation are stored.

The possible usages are:

- ``INCR ACC``
- ``INCR A``
- ``INCR B``
- ``INCR C``

DECR
^^^^

The ``DECR`` operation subracts one from the given argument (in place). The ALU
flags generated by this operation are stored.

The possible usages are:

- ``DECR ACC``
- ``DECR A``
- ``DECR B``
- ``DECR C``

Data Operations
---------------

Expand Down Expand Up @@ -395,9 +462,9 @@ followed the label definition. E.g. If an assembly file looked like this:
@label
SET B #42
The value of ``@label`` would be 3. The instruction byte corresponding to ``SET
B #42`` is at program memory index 3. ``LOAD [#123] A`` takes 2 bytes, ``ADD A``
one, and ``SET B #42`` is the byte after that.
The value of ``@label`` would be 3. The instruction byte corresponding to
``SET B #42`` is at program memory index 3. ``LOAD [#123] A`` takes 2 bytes,
``ADD A`` one, and ``SET B #42`` is the byte after that.

Labels are typically used by jump operations.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
eight\_bit\_computer.operations.addc\_op module
===============================================

.. automodule:: eight_bit_computer.operations.addc_op
:members:
:undoc-members:
:show-inheritance:
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
eight\_bit\_computer.operations.decr\_op module
===============================================

.. automodule:: eight_bit_computer.operations.decr_op
:members:
:undoc-members:
:show-inheritance:
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
eight\_bit\_computer.operations.incr\_op module
===============================================

.. automodule:: eight_bit_computer.operations.incr_op
:members:
:undoc-members:
:show-inheritance:
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
eight\_bit\_computer.operations.lshift\_op module
=================================================

.. automodule:: eight_bit_computer.operations.lshift_op
:members:
:undoc-members:
:show-inheritance:
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
eight\_bit\_computer.operations.lshiftc\_op module
==================================================

.. automodule:: eight_bit_computer.operations.lshiftc_op
:members:
:undoc-members:
:show-inheritance:
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
eight\_bit\_computer.operations.nand\_op module
===============================================

.. automodule:: eight_bit_computer.operations.nand_op
:members:
:undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/software/source/eight_bit_computer.operations.nor_op.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
eight\_bit\_computer.operations.nor\_op module
==============================================

.. automodule:: eight_bit_computer.operations.nor_op
:members:
:undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/software/source/eight_bit_computer.operations.not_op.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
eight\_bit\_computer.operations.not\_op module
==============================================

.. automodule:: eight_bit_computer.operations.not_op
:members:
:undoc-members:
:show-inheritance:
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
eight\_bit\_computer.operations.nxor\_op module
===============================================

.. automodule:: eight_bit_computer.operations.nxor_op
:members:
:undoc-members:
:show-inheritance:
11 changes: 11 additions & 0 deletions docs/software/source/eight_bit_computer.operations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,29 @@ Submodules
.. toctree::

eight_bit_computer.operations.add
eight_bit_computer.operations.addc_op
eight_bit_computer.operations.and_op
eight_bit_computer.operations.copy_op
eight_bit_computer.operations.decr_op
eight_bit_computer.operations.fetch
eight_bit_computer.operations.incr_op
eight_bit_computer.operations.jump
eight_bit_computer.operations.jump_if_flag_base
eight_bit_computer.operations.jump_if_overflow_flag
eight_bit_computer.operations.load
eight_bit_computer.operations.lshift_op
eight_bit_computer.operations.lshiftc_op
eight_bit_computer.operations.nand_op
eight_bit_computer.operations.nor_op
eight_bit_computer.operations.not_op
eight_bit_computer.operations.nxor_op
eight_bit_computer.operations.operation_template
eight_bit_computer.operations.or_op
eight_bit_computer.operations.set_op
eight_bit_computer.operations.simple_alu_op_base
eight_bit_computer.operations.sub
eight_bit_computer.operations.subb_op
eight_bit_computer.operations.xor_op

Module contents
---------------
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
eight\_bit\_computer.operations.subb\_op module
===============================================

.. automodule:: eight_bit_computer.operations.subb_op
:members:
:undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/software/source/eight_bit_computer.operations.xor_op.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
eight\_bit\_computer.operations.xor\_op module
==============================================

.. automodule:: eight_bit_computer.operations.xor_op
:members:
:undoc-members:
:show-inheritance:
2 changes: 1 addition & 1 deletion src/eight_bit_computer/assembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def validate_and_identify_constants(machine_code_bytes):
function then validates them to make sure they are correct and
determines what kind of constant they are.
See :func:`~.get_mc_byte_template` for information on
See :func:`~.get_machine_code_byte_template` for information on
machine code dictionaries from instructions.
This function modifies the passed in machine code templates list
Expand Down
1 change: 1 addition & 0 deletions src/eight_bit_computer/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def create_arduino_header(rom_index, file_prefix):
Create arduino header file
The header file looks like this::
#ifndef ROM_0_H
#define ROM_0_H
Expand Down
40 changes: 34 additions & 6 deletions src/eight_bit_computer/language_defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,20 @@

ALU_CONTROL_FLAGS = {
"A_PLUS_1": [

MODULE_CONTROL["ALU"]["S0_LOW"],
MODULE_CONTROL["ALU"]["S1_LOW"],
MODULE_CONTROL["ALU"]["S2_LOW"],
MODULE_CONTROL["ALU"]["S3_LOW"],
MODULE_CONTROL["ALU"]["M_LOW"],
MODULE_CONTROL["ALU"]["WITH_CARRY"],
],
"A_MINUS_1": [
MODULE_CONTROL["ALU"]["S0_HIGH"],
MODULE_CONTROL["ALU"]["S1_HIGH"],
MODULE_CONTROL["ALU"]["S2_HIGH"],
MODULE_CONTROL["ALU"]["S3_HIGH"],
MODULE_CONTROL["ALU"]["M_LOW"],
MODULE_CONTROL["ALU"]["NO_CARRY"],
],
"A_PLUS_B": [
MODULE_CONTROL["ALU"]["S0_HIGH"],
Expand All @@ -175,13 +188,23 @@
MODULE_CONTROL["ALU"]["S2_HIGH"],
MODULE_CONTROL["ALU"]["S3_LOW"],
MODULE_CONTROL["ALU"]["M_LOW"],
MODULE_CONTROL["ALU"]["NO_CARRY"],
MODULE_CONTROL["ALU"]["WITH_CARRY"],
],
"A_PLUS_B_PLUS_1": [

MODULE_CONTROL["ALU"]["S0_HIGH"],
MODULE_CONTROL["ALU"]["S1_LOW"],
MODULE_CONTROL["ALU"]["S2_LOW"],
MODULE_CONTROL["ALU"]["S3_HIGH"],
MODULE_CONTROL["ALU"]["M_LOW"],
MODULE_CONTROL["ALU"]["WITH_CARRY"],
],
"A_MINUS_B_MINS_1": [

"A_MINUS_B_MINUS_1": [
MODULE_CONTROL["ALU"]["S0_LOW"],
MODULE_CONTROL["ALU"]["S1_HIGH"],
MODULE_CONTROL["ALU"]["S2_HIGH"],
MODULE_CONTROL["ALU"]["S3_LOW"],
MODULE_CONTROL["ALU"]["M_LOW"],
MODULE_CONTROL["ALU"]["NO_CARRY"],
],
"A_AND_B": [
MODULE_CONTROL["ALU"]["S0_HIGH"],
Expand Down Expand Up @@ -240,7 +263,12 @@
MODULE_CONTROL["ALU"]["NO_CARRY"],
],
"A_PLUS_A": [

MODULE_CONTROL["ALU"]["S0_LOW"],
MODULE_CONTROL["ALU"]["S1_LOW"],
MODULE_CONTROL["ALU"]["S2_HIGH"],
MODULE_CONTROL["ALU"]["S3_HIGH"],
MODULE_CONTROL["ALU"]["M_LOW"],
MODULE_CONTROL["ALU"]["NO_CARRY"],
],
"A_PLUS_A_PLUS_1": [

Expand Down
14 changes: 13 additions & 1 deletion src/eight_bit_computer/operations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ def get_all_operations():
set_op,
jump,
jump_if_overflow_flag,
lshift_op,
lshiftc_op,
incr_op,
decr_op,
addc_op,
subb_op
)

return [
Expand All @@ -45,5 +51,11 @@ def get_all_operations():
load,
set_op,
jump,
jump_if_overflow_flag
jump_if_overflow_flag,
lshift_op,
lshiftc_op,
incr_op,
decr_op,
addc_op,
subb_op,
]

0 comments on commit 6c1197c

Please sign in to comment.