Skip to content

Commit

Permalink
Merge pull request #72 from ninezerozeronine/add_jump_if_flag_ops
Browse files Browse the repository at this point in the history
Add jump if flag ops. Update tox to fix coverage/coveralls version dependency bug.
  • Loading branch information
ninezerozeronine committed Dec 18, 2019
2 parents 6c1197c + 425ddbe commit 545ff0d
Show file tree
Hide file tree
Showing 17 changed files with 786 additions and 2 deletions.
59 changes: 58 additions & 1 deletion docs/language/assembly.rst
Original file line number Diff line number Diff line change
Expand Up @@ -299,14 +299,31 @@ JUMP_IF_EQ_ZERO
JUMP_IF_POSITIVE_FLAG
^^^^^^^^^^^^^^^^^^^^^

The ``JUMP_IF_POSITIVE_FLAG`` operation will set the program counter to the
value of a given constant if the last operation that the ALU flags were
stored for resulted in a positive value (when read as 2's compliment).

The possible usages are:

- ``JUMP_IF_POSITIVE_FLAG CONST``

JUMP_IF_NEGATIVE_FLAG
^^^^^^^^^^^^^^^^^^^^^

The ``JUMP_IF_NEGATIVE_FLAG`` operation will set the program counter to the
value of a given constant if the last operation that the ALU flags were
stored for resulted in a negative value (when read as 2's compliment).

The possible usages are:

- ``JUMP_IF_NEGATIVE_FLAG CONST``

JUMP_IF_OVERFLOW_FLAG
^^^^^^^^^^^^^^^^^^^^^

The ``JUMP_IF_OVERFLOW_FLAG`` operation will set the program counter to the
value of a given constant if the overflow flag is high.
value of a given constant if the last operation that the ALU flags were
stored for resulted in an overflow.

The possible usages are:

Expand All @@ -315,18 +332,58 @@ The possible usages are:
JUMP_IF_NOT_OVERFLOW_FLAG
^^^^^^^^^^^^^^^^^^^^^^^^^

The ``JUMP_IF_OVERFLOW_FLAG`` operation will set the program counter to the
value of a given constant if the last operation that the ALU flags were
stored for did not result in an overflow.

The possible usages are:

- ``JUMP_IF_NOT_OVERFLOW_FLAG CONST``

JUMP_IF_UNDERFLOW_FLAG
^^^^^^^^^^^^^^^^^^^^^^

The ``JUMP_IF_UNDERFLOW_FLAG`` operation will set the program counter to the
value of a given constant if the last operation that the ALU flags were
stored for resulted in an underflow.

The possible usages are:

- ``JUMP_IF_UNDERFLOW_FLAG CONST``

JUMP_IF_NOT_UNDERFLOW_FLAG
^^^^^^^^^^^^^^^^^^^^^^^^^^

The ``JUMP_IF_NOT_UNDERFLOW_FLAG`` operation will set the program counter to the
value of a given constant if the last operation that the ALU flags were
stored for did not result in an underflow.

The possible usages are:

- ``JUMP_IF_NOT_UNDERFLOW_FLAG CONST``

JUMP_IF_ZERO_FLAG
^^^^^^^^^^^^^^^^^

The ``JUMP_IF_ZERO_FLAG`` operation will set the program counter to the
value of a given constant if the last operation that the ALU flags were
stored for resulted in an answer of zero.

The possible usages are:

- ``JUMP_IF_ZERO_FLAG CONST``

JUMP_IF_NOT_ZERO_FLAG
^^^^^^^^^^^^^^^^^^^^^

The ``JUMP_IF_NOT_ZERO_FLAG`` operation will set the program counter to the
value of a given constant if the last operation that the ALU flags were
stored for resulted in a non zero answer.

The possible usages are:

- ``JUMP_IF_NOT_ZERO_FLAG CONST``

CALL
^^^^

Expand Down
14 changes: 14 additions & 0 deletions src/eight_bit_computer/operations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ def get_all_operations():
load,
set_op,
jump,
jump_if_positive_flag,
jump_if_negative_flag,
jump_if_overflow_flag,
jump_if_not_overflow_flag,
jump_if_underflow_flag,
jump_if_not_underflow_flag,
jump_if_zero_flag,
jump_if_not_zero_flag,
lshift_op,
lshiftc_op,
incr_op,
Expand All @@ -51,7 +58,14 @@ def get_all_operations():
load,
set_op,
jump,
jump_if_positive_flag,
jump_if_negative_flag,
jump_if_overflow_flag,
jump_if_not_overflow_flag,
jump_if_underflow_flag,
jump_if_not_underflow_flag,
jump_if_zero_flag,
jump_if_not_zero_flag,
lshift_op,
lshiftc_op,
incr_op,
Expand Down
41 changes: 41 additions & 0 deletions src/eight_bit_computer/operations/jump_if_negative_flag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
JUMP_IF_NEGATIVE_FLAG operation
"""

from . import jump_if_flag_base
from ..language_defs import FLAGS

_NAME = "JUMP_IF_NEGATIVE_FLAG"


def generate_microcode_templates():
"""
Generate microcode for all the JUMP_IF_NEGATIVE_FLAG instructions.
Returns:
list(DataTemplate): DataTemplates for all the
JUMP_IF_NEGATIVE_FLAG instructions.
"""

return jump_if_flag_base.generate_microcode_templates(
"C",
FLAGS["NEGATIVE"]["HIGH"],
FLAGS["NEGATIVE"]["LOW"],
)


def parse_line(line):
"""
Parse a line of assembly code to create machine code byte templates.
If a line is not identifiably a JUMP_IF_NEGATIVE_FLAG assembly line,
return an empty list instead.
Args:
line (str): Assembly line to be parsed.
Returns:
list(dict): List of machine code byte template dictionaries or
an empty list.
"""

return jump_if_flag_base.parse_line(line, "C", _NAME)
41 changes: 41 additions & 0 deletions src/eight_bit_computer/operations/jump_if_not_overflow_flag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
JUMP_IF_NOT_OVERFLOW_FLAG operation
"""

from . import jump_if_flag_base
from ..language_defs import FLAGS

_NAME = "JUMP_IF_NOT_OVERFLOW_FLAG"


def generate_microcode_templates():
"""
Generate microcode for all the JUMP_IF_NOT_OVERFLOW_FLAG instructions.
Returns:
list(DataTemplate): DataTemplates for all the
JUMP_IF_NOT_OVERFLOW_FLAG instructions.
"""

return jump_if_flag_base.generate_microcode_templates(
"PC",
FLAGS["CARRY_BORROW"]["LOW"],
FLAGS["CARRY_BORROW"]["HIGH"],
)


def parse_line(line):
"""
Parse a line of assembly code to create machine code byte templates.
If a line is not identifiably a JUMP_IF_NOT_OVERFLOW_FLAG assembly line,
return an empty list instead.
Args:
line (str): Assembly line to be parsed.
Returns:
list(dict): List of machine code byte template dictionaries or
an empty list.
"""

return jump_if_flag_base.parse_line(line, "PC", _NAME)
41 changes: 41 additions & 0 deletions src/eight_bit_computer/operations/jump_if_not_underflow_flag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
JUMP_IF_NOT_UNDERFLOW_FLAG operation
"""

from . import jump_if_flag_base
from ..language_defs import FLAGS

_NAME = "JUMP_IF_NOT_UNDERFLOW_FLAG"


def generate_microcode_templates():
"""
Generate microcode for all the JUMP_IF_NOT_UNDERFLOW_FLAG instructions.
Returns:
list(DataTemplate): DataTemplates for all the
JUMP_IF_NOT_UNDERFLOW_FLAG instructions.
"""

return jump_if_flag_base.generate_microcode_templates(
"CONST",
FLAGS["CARRY_BORROW"]["HIGH"],
FLAGS["CARRY_BORROW"]["LOW"],
)


def parse_line(line):
"""
Parse a line of assembly code to create machine code byte templates.
If a line is not identifiably a JUMP_IF_NOT_UNDERFLOW_FLAG assembly line,
return an empty list instead.
Args:
line (str): Assembly line to be parsed.
Returns:
list(dict): List of machine code byte template dictionaries or
an empty list.
"""

return jump_if_flag_base.parse_line(line, "CONST", _NAME)
41 changes: 41 additions & 0 deletions src/eight_bit_computer/operations/jump_if_not_zero_flag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
JUMP_IF_NOT_ZERO_FLAG operation
"""

from . import jump_if_flag_base
from ..language_defs import FLAGS

_NAME = "JUMP_IF_NOT_ZERO_FLAG"


def generate_microcode_templates():
"""
Generate microcode for all the JUMP_IF_NOT_ZERO_FLAG instructions.
Returns:
list(DataTemplate): DataTemplates for all the
JUMP_IF_NOT_ZERO_FLAG instructions.
"""

return jump_if_flag_base.generate_microcode_templates(
"A",
FLAGS["ZERO"]["LOW"],
FLAGS["ZERO"]["HIGH"],
)


def parse_line(line):
"""
Parse a line of assembly code to create machine code byte templates.
If a line is not identifiably a JUMP_IF_NOT_ZERO_FLAG assembly line,
return an empty list instead.
Args:
line (str): Assembly line to be parsed.
Returns:
list(dict): List of machine code byte template dictionaries or
an empty list.
"""

return jump_if_flag_base.parse_line(line, "A", _NAME)
41 changes: 41 additions & 0 deletions src/eight_bit_computer/operations/jump_if_positive_flag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
JUMP_IF_POSITIVE_FLAG operation
"""

from . import jump_if_flag_base
from ..language_defs import FLAGS

_NAME = "JUMP_IF_POSITIVE_FLAG"


def generate_microcode_templates():
"""
Generate microcode for all the JUMP_IF_POSITIVE_FLAG instructions.
Returns:
list(DataTemplate): DataTemplates for all the
JUMP_IF_POSITIVE_FLAG instructions.
"""

return jump_if_flag_base.generate_microcode_templates(
"B",
FLAGS["NEGATIVE"]["LOW"],
FLAGS["NEGATIVE"]["HIGH"],
)


def parse_line(line):
"""
Parse a line of assembly code to create machine code byte templates.
If a line is not identifiably a JUMP_IF_POSITIVE_FLAG assembly line,
return an empty list instead.
Args:
line (str): Assembly line to be parsed.
Returns:
list(dict): List of machine code byte template dictionaries or
an empty list.
"""

return jump_if_flag_base.parse_line(line, "B", _NAME)
41 changes: 41 additions & 0 deletions src/eight_bit_computer/operations/jump_if_underflow_flag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
JUMP_IF_UNDERFLOW_FLAG operation
"""

from . import jump_if_flag_base
from ..language_defs import FLAGS

_NAME = "JUMP_IF_UNDERFLOW_FLAG"


def generate_microcode_templates():
"""
Generate microcode for all the JUMP_IF_UNDERFLOW_FLAG instructions.
Returns:
list(DataTemplate): DataTemplates for all the
JUMP_IF_UNDERFLOW_FLAG instructions.
"""

return jump_if_flag_base.generate_microcode_templates(
"SP+/-",
FLAGS["CARRY_BORROW"]["LOW"],
FLAGS["CARRY_BORROW"]["HIGH"],
)


def parse_line(line):
"""
Parse a line of assembly code to create machine code byte templates.
If a line is not identifiably a JUMP_IF_UNDERFLOW_FLAG assembly line,
return an empty list instead.
Args:
line (str): Assembly line to be parsed.
Returns:
list(dict): List of machine code byte template dictionaries or
an empty list.
"""

return jump_if_flag_base.parse_line(line, "SP+/-", _NAME)

0 comments on commit 545ff0d

Please sign in to comment.