From b3d8ee98258c1cf0dfa620630bc81b8f73b5e299 Mon Sep 17 00:00:00 2001 From: Giulio De Pasquale Date: Sat, 20 May 2017 19:13:04 +0200 Subject: [PATCH] label offset corretto --- assembler/assembler.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/assembler/assembler.py b/assembler/assembler.py index abf574b..54bc17b 100644 --- a/assembler/assembler.py +++ b/assembler/assembler.py @@ -55,7 +55,6 @@ class VMAssembler: self.functions = [] self.decrypt_ops(key) self.parse_functions() - print(self.functions) main = next((x for x in self.functions if x.name == "main"), None) if main == None: print("Main has to be defined") @@ -102,7 +101,6 @@ class VMAssembler: """ Intel syntax -> REG, IMM """ - print(instruction.args) opcode = instruction.opcode reg = instruction.args[0] imm = instruction.args[1] @@ -219,6 +217,7 @@ class VMAssembler: for i in f.instructions: if i.label == dst.name: val = f.offset_of_label(dst) + f.offset + if val == None: raise AssemblerException() # resolving the symbol @@ -269,14 +268,11 @@ class VMFunction: line = code[i] ins = instruction_re.match(line) label = label_re.match(line) - print(line) if label: label_name = label.group(1) - print("APPENDING {} TO {}".format(code[i], self.name)) self.instructions.append(VMInstruction(code[i+1], label_name)) i += 2 elif ins: - print("APPENDING {} TO {}".format(code[i], self.name)) self.instructions.append(VMInstruction(line)) else: raise InvalidOperation(line) @@ -293,9 +289,10 @@ class VMFunction: def offset_of_label(self, label): offset = 0 for i in self.instructions: - offset += i.size - if i.label == label: + if str(i.label) == str(label): break + offset += i.size + return offset def __repr__(self): @@ -324,9 +321,7 @@ class VMInstruction: raise InvalidOperation(opcode) args = [x for x in ins.groups()[1:] if x is not None] - print(args) for a in args: - print(a) if immediate_re.match(a) or symcall: # directly append the immediate self.args.append(VMComponent(a, a))