Exemplo n.º 1
1
class TestAssembler(unittest.TestCase):
    def setUp(self):
        self.asm = Assembler()
        self.asm.load_file("SICXE.txt")

    def test_read_source(self):
        self.assertIsNotNone(self.asm.source, "Can't read file")
        print("=====Source code=====")
        for i in self.asm.source:
            print("{1}\t{0}\t{2}".format(i['operator'],
                                         i['symbol'] if i['symbol'] else "\t",
                                         i['operand'] if i['operand'] else "\t"))

    def test_load_operators(self):
        load_op = self.asm.load_operators('Operators.dat')
        self.assertIsNotNone(load_op)
        print(load_op)

    def test_append_operator(self):
        add_op = self.asm.append_operator('ADD', '0x18', 3)
        self.assertIsNotNone(add_op)
        print(add_op)

    def test_operator_table(self):
        print("=======OPTAB========")
        for i, val in self.asm.OPTAB.items():
            print(" {:6}\t{:2}\t{:02X}".format(i, val['format'], int(val['opcode'], 16)))

    def test_symbol_table(self):
        self.asm.pass_one()
        self.asm.pass_two()
        print("======SYMTAB======")
        print("{:^8}\t{:^5}".format('"symbol"', '"val"'))
        for i, val in self.asm.SYMTAB.items():
            print(" {:8}\t{:04X}".format(i, val))

    def test_literal(self):
        self.asm.pass_one()
        self.asm.pass_two()
        print("=======LITERALS========")
        for i, val in self.asm.LITERAL.items():
            print(" {:7}\t{:04X}".format(i, val))

    def test_record(self):
        self.asm.pass_one()
        self.asm.pass_two()
        print("======Object Program=====")
        print(self.asm.object_program)
Exemplo n.º 2
0
 def setUp(self):
     self.asm = Assembler()
     self.asm.load_file("SICXE.txt")
Exemplo n.º 3
0
import sys
from SICXE import Assembler

if __name__ == '__main__':
    try:
        file = sys.argv[1]
    except IndexError:
        file = input("Please input a full file name...>")

    while not file:
        print("You don't input a file.")
        file = input("Please input again...>")

    asm = Assembler().load_file(file)
    print("=====Source code=====")
    for i in asm.source:
        print("{1}\t{0}\t{2}".format(i['operator'],
                                     i['symbol'] if i['symbol'] else "\t",
                                     i['operand'] if i['operand'] else "\t"))
    print("\n=======OPTAB========\n")
    for i, val in asm.OPTAB.items():
        print(" {:6}\t{:2}\t{:02X}".format(i, val['format'], int(val['opcode'], 16)))

    asm.pass_one()
    print("\n======SYMTAB======\n")
    print("{:^8}\t{:^5}".format('"symbol"', '"val"'))
    for i, val in asm.SYMTAB.items():
        print(" {:8}\t{:04X}".format(i, val))
    if asm.LITERAL:
        print("\n=======LITERALS========\n")
        for i, val in asm.LITERAL.items():