def test_circular(): circular = "" for i in original: circular += disassemble(i) + "\n" print(circular) code2 = Assembler(data=circular) code2.assemble() code2.display()
def line(asmblr): pc = str(cpu.pc).ljust(10) code = disassemble(cpu.mem[cpu.pc]).ljust(20) reg = cpu.mem[0:8].tolist() stack = cpu.mem[9:25].tolist() if cpu.mem[cpu.pc] in asmblr.rev_labels: ref = asmblr.rev_labels[cpu.mem[cpu.pc]] else: ref = "" if cpu.pc in asmblr.rev_labels: label = asmblr.rev_labels[cpu.pc] else: label = "" print(pc, "|", code, "|", reg, "|", stack, "->", label, "|", ref, "\r")
def display(self): # reverse labels for disasm listing for i, j in self.labels.items(): self.rev_labels[j] = i for offset, code in enumerate(self.code): l = "" if offset in self.rev_labels: l = self.rev_labels[offset] o = "{:05d} | ".format(offset) if isinstance(code, int): if (code < 31) or code == 128: b = " | _ ," + str(int(code)) else: b = " | " + chr(code) + "," + str(int(code)) else: b = 0 code = 0 print(o, l.ljust(10), " | ", disassemble(code).ljust(16), b)
"pwmon", STX(R1, R0, 0), "pwmdone", SUBI(R2, 1), JNZ("breathe"), J("loop"), ]), ] print("---------------------- compare ----------------") for i, j in enumerate(original): if original[i] != assembled[i]: print("----------------- error ----------------") print( str(i).ljust(5), "|", disassemble(original[i]).ljust(30), "|", disassemble(assembled[i]).ljust(30), "|", ) def test_circular(): circular = "" for i in original: circular += disassemble(i) + "\n" print(circular) code2 = Assembler(data=circular) code2.assemble() code2.display()
class class_a(metaclass=opcode): op = 0b0000 pass class class_s(metaclass=opcode): op = 0b0000 pass class class_m(metaclass=opcode): op = 0b0010 pass class class_i(metaclass=opcode): op = 0b0100 pass class class_c(metaclass=opcode): op = 0b1000 pass print(class_a()) for i in range(2**BITS): print(i, disassemble(i))