Skip to content

Commit

Permalink
Merge pull request #1 from dmykyten/mykytenko
Browse files Browse the repository at this point in the history
  • Loading branch information
dmykyten authored Dec 27, 2022
2 parents 51337cc + 516f4bd commit 999e72e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
11 changes: 5 additions & 6 deletions modules/assembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,8 @@ def preprocess(self, text : str):

# If the label is mentioned with directive specification and its value, we have to encode it into memory
elif len(words) == 3:
if words[1] == "db":
self.mov_labels[words[0]] = self.__decode_directive(True, words[2])
elif words[1] == "dw":
self.mov_labels[words[0]] = self.__decode_directive(False, words[2])
if words[1] in ["db", "dw"]:
self.mov_labels[words[0]] = self.__decode_directive(words[1], words[2])
else:
raise AssemblerError("Provide a valid assembly directive")

Expand All @@ -258,15 +256,16 @@ def preprocess(self, text : str):
return result_text

@staticmethod
def __decode_directive(is_byte, value):
def __decode_directive(directive, value):
"""
Decodes operands for directives (db, dw)
:param is_byte: bool - to encode value in a byte or word
:param directive: str - valid assembly directive
:param value: str - an operand to encode
"""
# We just figure out what's being encoded into bits - a number (which should fit in 8/16 bits) or a string of
# characters (every ASCII character is 1 byte), and return the value we found
is_byte = directive == 'db'
limits = (-2 ** 7 + 1, 2 ** 8) if is_byte else (-2 ** 15 + 1, 2 ** 16)
int_pattern = r"^\d+$"
str_pattern = r"^\"[a-zA-Z0-9\\]+\"$"
Expand Down
17 changes: 16 additions & 1 deletion modules/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,12 @@

# TODO: Should we have a SIMD switch on / off for CISC?

# DONE:
# * at the moment commented out curses functionality

import os
import json
import curses
# import curses
import logging
from bitarray import bitarray
from bitarray.util import ba2hex
Expand Down Expand Up @@ -178,6 +181,9 @@ def __init__(self, isa, architecture, io_arch, program_text, program_start=512,

self.instruction = bitarray('')

'''
Deprecated curses functionality
# Draw the main interface
if self.curses_mode:
self.start_screen()
Expand All @@ -192,6 +198,7 @@ def __init__(self, isa, architecture, io_arch, program_text, program_start=512,
# Close the curses module screen if we are in its mode
self.close_screen()
'''

def __create_registers(self):
"""
Expand Down Expand Up @@ -336,9 +343,13 @@ def __execute_cycle(self):
Execute the current instruction, and move on to the next one, moving the instruction pointer
"""
is_close = False
'''
Deprecated curses functionality
# Waiting for the key or button to be pressed, depending on the mode
if self.curses_mode:
is_close = self.curses_next_instruction()
'''

# Executing the instruction if it's not a 'nop' - no operation instruction
if (instr_name := self.instructions_dict[self.opcode.to01()][0]) == "nop":
Expand Down Expand Up @@ -913,6 +924,9 @@ def input_finish(self, char):
else:
self.input_result_destination.write_data(char)

'''
Deprecated curses functionality
# Below are the methods for curses-driven command-line interface
def start_program(self):
"""
Expand Down Expand Up @@ -1078,6 +1092,7 @@ def close_screen(self):
self.std_screen.keypad(False)
curses.curs_set(True)
curses.endwin()
'''


class SimulatorError(Exception):
Expand Down

0 comments on commit 999e72e

Please sign in to comment.