def main(): file_in, file_out = parse_args() src_lines = file_in.readlines() lines, err = parse_lines(src_lines) file_in.close() if len(err) > 0: print "Syntax errors:" print_errors(err) file_out.close() return errors.ERR_SYNTAX[0] asm = Assembler() asm.run(lines) memory_table = asm.memory start_address = asm.start_address err = asm.errors if len(err) > 0: print "Assemble errors:" print_errors(err) file_out.close() return errors.ERR_ASSEMBLE[0] if start_address is not None: print "Start address: %04i" % start_address if memory_table is not None: print "Memory:" write_memory(sys.stdout, memory_table.memory) write_asm_file(file_out, start_address, memory_table.memory) file_out.close()
def testWithAssembler(self): src_lines = """\ STart eNTA =-0= this is start of my mega program LABEL1 \tStA LABEL1 sample of self modified code * i love this program * empty lines \toRIg 1000 equ 18 device 9H hlt eND 0 and this is my long long poem""".splitlines() lines = [ Line("START", "ENTA", "=-0=", 1, 0), Line("LABEL1", "STA", "LABEL1", 2, 1), Line(None, "ORIG", "1000", 8), Line(None, "EQU", "18", 9), Line("9H", "HLT", None, 10, 1000), Line(None, "END", "0", 11) ] asm = Assembler() asm.run(lines) result = [ ListingLine(0, [+1, 15, 41, 0, 2, 48], "STart eNTA =-0= this is start of my mega program"), ListingLine(1, [+1, 0, 1, 0, 5, 24], "LABEL1 \tStA LABEL1 sample of self modified code"), ListingLine(None, None, "* i love this program"), ListingLine(None, None, ""), ListingLine(None, None, "* empty lines"), ListingLine(None, None, ""), ListingLine(None, None, ""), ListingLine(None, None, "\toRIg 1000"), ListingLine(None, None, " equ 18 device"), ListingLine(1000, [+1, 0, 0, 0, 2, 5], "9H hlt"), ListingLine(None, None, " eND 0"), ListingLine(None, None, " and this is my"), ListingLine(None, None, " long"), ListingLine(None, None, " long poem"), ListingLine(1001, [-1, 0, 0, 0, 0, 0], "\tCON\t-0") ] self.check(src_lines, lines, asm.memory.memory, asm.symtable.literals, asm.end_address, result)
def assemble_program(self, fname): with open(fname, "r") as f: lines, errors = parse_lines(f.readlines()) if errors != []: print "------------------------------\n",fname, '\nParse_line errors:' print_errors(errors) self.assertEqual(errors, []) asm = Assembler() asm.run(lines) if asm.errors != []: print "------------------------------\n",fname, '\nAssemble errors:' print_errors(asm.errors) self.assertEqual(asm.errors, [])
def testWithAssembler(self): src_lines = """\ STart eNTA =-0= this is start of my mega program LABEL1 \tStA LABEL1 sample of self modified code * i love this program * empty lines \toRIg 1000 equ 18 device 9H hlt eND 0 and this is my long long poem""".splitlines() lines = [ Line("START", "ENTA", "=-0=", 1, 0), Line("LABEL1", "STA", "LABEL1", 2, 1), Line(None, "ORIG", "1000", 8), Line(None, "EQU", "18", 9), Line("9H", "HLT", None, 10, 1000), Line(None, "END", "0", 11) ] asm = Assembler() asm.run(lines) result = [ ListingLine( 0, [+1, 15, 41, 0, 2, 48], "STart eNTA =-0= this is start of my mega program"), ListingLine( 1, [+1, 0, 1, 0, 5, 24], "LABEL1 \tStA LABEL1 sample of self modified code"), ListingLine(None, None, "* i love this program"), ListingLine(None, None, ""), ListingLine(None, None, "* empty lines"), ListingLine(None, None, ""), ListingLine(None, None, ""), ListingLine(None, None, "\toRIg 1000"), ListingLine(None, None, " equ 18 device"), ListingLine(1000, [+1, 0, 0, 0, 2, 5], "9H hlt"), ListingLine(None, None, " eND 0"), ListingLine(None, None, " and this is my"), ListingLine(None, None, " long"), ListingLine(None, None, " long poem"), ListingLine(1001, [-1, 0, 0, 0, 0, 0], "\tCON\t-0") ] self.check(src_lines, lines, asm.memory.memory, asm.symtable.literals, asm.end_address, result)