def print_section(self, start, amount): """ Print a section of the cache. :param int start: start address to print from. :param int amount: amount of lines to print. """ line_len = len(str(self.size // self.block_size - 1)) use_len = max([len(str(line.use)) for line in self.lines]) tag_len = int( log((self.mapping_policy * self.memory_size) // self.size, 2)) address_len = int(log(self.memory_size, 2)) if start < 0 or (start + amount) > (self.size // self.block_size): raise IndexError print("\n" + " " * line_len + " " * use_len + " U M V T" + " " * tag_len + "<DATA @ ADDRESS>") for i in range(start, start + amount): print("%s : %s %s %s %s <%s @ %s>" % (util.dec_str( i, line_len), util.dec_str(self.lines[i].use, use_len), util.bin_str(self.lines[i].modified, 1), util.bin_str(self.lines[i].valid, 1), util.bin_str(self.lines[i].tag, tag_len), " ".join( [util.hex_str(j, 2) for j in self.lines[i].data]), util.bin_str(self.get_physical_address(i), address_len))) print()
def print_section(self, start, amount): """Print a section of the cache. :param int start: start address to print from :param int amount: amount of lines to print """ line_len = len(str(self._size // self._block_size - 1)) use_len = max([len(str(i.use)) for i in self._lines]) tag_len = int(log(self._mapping_pol * self._mem_size // self._size, 2)) address_len = int(log(self._mem_size, 2)) if start < 0 or (start + amount) > (self._size // self._block_size): raise IndexError print("\n" + " " * line_len + " " * use_len + " U M V T" + " " * tag_len + "<DATA @ ADDRESS>") for i in range(start, start + amount): print( util.dec_str(i, line_len) + ": " + util.dec_str(self._lines[i].use, use_len) + " " + util.bin_str(self._lines[i].modified, 1) + " " + util.bin_str(self._lines[i].valid, 1) + " " + util.bin_str(self._lines[i].tag, tag_len) + " <" + " ".join([util.hex_str(i, 2) for i in self._lines[i].data]) + " @ " + util.bin_str(self.get_physical_address(i), address_len) + ">") print()
def print_section(self, start, amount): """Print a section of the cache. :param int start: start address to print from :param int amount: amount of lines to print """ line_len = len(str(self._size // self._block_size - 1)) use_len = max([len(str(i.use)) for i in self._lines]) tag_len = int(log(self._mapping_pol * self._mem_size // self._size, 2)) address_len = int(log(self._mem_size, 2)) if start < 0 or (start + amount) > (self._size // self._block_size): raise IndexError print("\n" + " " * line_len + " " * use_len + " U M V T" + " " * tag_len + "<DATA @ ADDRESS>") for i in range(start, start + amount): print(util.dec_str(i, line_len) + ": " + util.dec_str(self._lines[i].use, use_len) + " " + util.bin_str(self._lines[i].modified, 1) + " " + util.bin_str(self._lines[i].valid, 1) + " " + util.bin_str(self._lines[i].tag, tag_len) + " <" + " ".join([util.hex_str(i, 2) for i in self._lines[i].data]) + " @ " + util.bin_str(self.get_physical_address(i), address_len) + ">") print()
def print_section(self, start, amount): """ Print a section of main memory. :param int start: start address to print from. :param int amount: amount of blocks to print. """ address_length = len(str(self.size - 1)) start = start - (start % self.block_size) amount *= self.block_size if start < 0 or (start + amount) > self.size: raise IndexError print() for i in range(start, start + amount, self.block_size): print( '%s:%s' % ( util.dec_str(i, address_length), " ".join( [ util.hex_str(j, 2) for j in self.get_block(i) ] ) ) ) print()
def print_section(self, start, amount): """Print a section of main memory. :param int start: start address to print from :param int amount: amount of blocks to print """ address_len = len(str(self._size - 1)) start = start - (start % self._block_size) amount *= self._block_size if start < 0 or (start + amount) > self._size: raise IndexError print() for i in range(start, start + amount, self._block_size): print(util.dec_str(i, address_len) + ": " + " ".join([util.hex_str(i, 2) for i in self.get_block(i)])) print()