# Get memory usage infile = open('main.map') for line in infile: if 'Section Info' in line: break for line in infile: if '-----' in line: break code_sum = 0 ram_sum = 0 for line in infile: if not line.strip(): break name, memtype, addr, location, size = line.strip().split() if 'UD_abs' in name: continue size = int(size.strip(), 0) if memtype.strip() == 'code': code_sum += size elif 'data' in memtype.strip(): ram_sum += size else: print "unknown memory type:", memtype print code_sum // 2, "code words", ram_sum, "ram bytes"