Пример #1
0
    def __init__(self, source):
        self.instructions = []
        self.machine_code = []
        self.registers = [0] * 32
        self.labels = {}
        self.pc = 0
        self.memory = stack.Stack()

        counter = 0
        for line in source:
            inst, found_labels = conv.convert_line(line, self.labels)
            for label in found_labels:
                self.labels[label] = counter
            new_instruction = ins.Instruction(self, line)
            self.machine_code.append(inst)
            self.instructions.append(new_instruction)
            counter += ins.Instruction.SIZE
Пример #2
0
    def __init__(self, source):
        self.instructions = []
        self.machine_code = []
        self.registers = [0] * 32
        self.registers[29] = 0x1000
        self.labels = {}
        self.pc = 0
        self.memory = stack.Stack(self.registers[29])
        self.hi = 0
        self.lo = 0

        counter = 0

        # build the label dictionary ahead of time
        addr_counter = 0
        for line in source:
            # remove comments and whitespace
            tokens = line.split("#")[0].split()
            tokens = [i.split(",")[0].lstrip().rstrip() for i in tokens]
            i = 0
            while i < len(tokens):
                if tokens[i].find(":") != -1:
                    self.labels[tokens[i][:-1]] = addr_counter
                    tokens.pop(i)
                else:
                    i += 1
            if len(tokens) > 0:
                addr_counter += ins.Instruction.SIZE

        # now create instructions
        line_counter = 0
        for line in source:
            inst = conv.convert_line(line, counter, self.labels)
            if inst != None:
                new_instruction = ins.Instruction(self, line, line_counter)
                self.machine_code.append(inst)
                self.instructions.append(new_instruction)
                counter += ins.Instruction.SIZE
            line_counter += 1
        self.inst_count = counter // 4
Пример #3
0
	def __init__(self, source):
		self.instructions = []
		self.machine_code = []
		self.registers = [0] * 32
		self.registers[29] = 0x1000
		self.labels = {}
		self.pc = 0
		self.memory = stack.Stack(self.registers[29])
		self.hi = 0
		self.lo = 0

		counter = 0

		# build the label dictionary ahead of time
		addr_counter = 0
		for line in source:
			# remove comments and whitespace
			tokens = line.split("#")[0].split()
			tokens = [i.split(",")[0].lstrip().rstrip() for i in tokens]
			i = 0
			while i < len(tokens):
				if tokens[i].find(":") != -1:
					self.labels[tokens[i][:-1]] = addr_counter
					tokens.pop(i)
				else:
					i += 1
			if len(tokens) > 0:
				addr_counter += ins.Instruction.SIZE

		# now create instructions
		line_counter = 0
		for line in source:
			inst = conv.convert_line(line, counter, self.labels)
			if inst != None:
				new_instruction = ins.Instruction(self, line, line_counter)
				self.machine_code.append(inst)
				self.instructions.append(new_instruction)
				counter += ins.Instruction.SIZE
			line_counter += 1
		self.inst_count = counter // 4