示例#1
0
	def read_memory(self, position, lines=1):
		"""Ler uma posição ou mais posição de memória.
		Retorna um dicionário com a informação lida em bytes, string e array.

		Keyword arguments:
		position -- Posição inicial de memória a ser lida
		lines -- Número de posições a ser lida a partir de position
		"""
		#Verifica se esta tentando ler mais do que existe na memoria
		if (position >= self.get_memory_size()):
			return None

		#Indicara a posicao a ser lida
		pos = None
		#Converte a posicao para inteiro
		if (type(position) == str):
			pos = convert_to_decimal(position)
		elif (type(position) == bytes):
			pos = int.from_bytes(position, byteorder="little")
		else:
			pos = position

		#Resultado da leitura em bytes
		result_byte = b""

		#Adiciona byte a byte os resultados
		for i in range(0, lines):
			result_byte += self._memory[pos+i]

		#Prepara resultado para ser mostrado em string
		result_str = ''
		for i in range(0, lines):
			int_value = int.from_bytes(self._memory[pos+i], "little")
			result_str += convert_to_bin(int_value)["bin_str"]

		#Prepara resultado para ser mostrado em listas
		result_arr = []
		for i in range(0, lines):
			int_value = int.from_bytes(self._memory[pos+i], "little")
			result_arr += convert_to_bin(int_value)["bin_arr"]

		#Retorna o dicionario da leitura de 3 formas diferentes
		return {
			"byte": result_byte,
			"str": result_str,
			"arr": result_arr
		}
示例#2
0
	def _define_arr_instruction(self):
		"""Retorna uma lista de 0 e 1 representando uma instrução de 8 bytes em binário"""
		instruction_arr = []

		for byte in self.instruction_byte:
			bin_dic = convert_to_bin(byte)
			instruction_arr += bin_dic['bin_arr']

		return instruction_arr
示例#3
0
	def _define_str_instruction(self):
		"""Define uma string representando a instrução de 8 bytes em binário"""
		instruction_str = ""

		for byte in self.instruction_byte:
			bin_dict = convert_to_bin(byte)
			instruction_str += bin_dict['bin_str'][::-1]

		return instruction_str[::-1]
示例#4
0
	def get_memory_arr(self):
		int_list = self.get_memory_int()
		return list(
			map(lambda elem: convert_to_bin(elem)["bin_arr"], int_list)
		)