示例#1
0
 def __init__(self, instructions):
   dataAddr = findDataAddress(instructions)
   self.instructions = instructions
   for i, instruction in enumerate(instructions):
     if i < dataAddr:
       continue
     else:
       self.instructions[i] = Word.convert32BitUnsignedToSigned(instruction)
示例#2
0
def output(machine, file): #file should be an open, write textually file
  out = ['']
  def p(x=''): out[0] += x + '\n' #quick helper function
  def bin(w):
    s = ''
    for i in range(31, -1, -1):
      s += str((w >> i) & 1)
    return s
  p('-' * 20)
  
  #debug mode
  #-----------------------------
  # p(str(machine.pc))
  # p(str(machine.hazard.active + machine.hazard.noIssued))
  # p(str(machine.shouldBreak))
  #-----------------------------
  
  p('Cycle:%d' % machine.cycleCount) #print the cycle
  p() #print a blank line
  p('Pre-Issue Buffer:')
  #for i, k in enumerate(machine.preIssue.buffer):
  for i in range(4):
    if i < len(machine.preIssue):
      k = machine.preIssue.buffer[i]
      p(('\tEntry %d:\t' % i)+'['+dissassemble(k)+']')
    else :
      p(('\tEntry %d:\t') %i)
  p('Pre_ALU Queue:')
  for i in range(2):
    if i < len(machine.preAlu):
      k = machine.preAlu.queue[(i + 1) * -1]['instruction']
      p(('\tEntry %d:\t' % i)+'['+dissassemble(k)+']')
    else :
      p(('\tEntry %d:\t') %i)
  p('Post_ALU Queue:')
  if len(machine.postAlu):
    p(('\tEntry %d:\t' % 0)+'['+dissassemble(machine.postAlu.entry['instruction'])+']')
  else:
    p('\tEntry %d:\t' % 0)
  p('Pre_MEM Queue:')
  for i in range(2):
    if i < len(machine.preMem):
      k = machine.preMem.queue[(i + 1) * -1]['instruction']
      p(('\tEntry %d:\t' % i)+'['+dissassemble(k)+']')
    else:
      p(('\tEntry %d:\t') %i)
  p('Post_MEM Queue:')
  if len(machine.postMem):
    p(('\tEntry %d:\t' % 0)+'['+dissassemble(machine.postMem.entry['instruction'])+']')
  else:
    p('\tEntry %d:\t' % 0)
  p() #print a blank line
  p('Registers')
  for i, v in enumerate(machine.registers):
    if(i % 8 == 0):
      out[0] += 'R%02d:' % i
    out[0] += '\t%d' % Word.convert32BitUnsignedToSigned(v)
    if(i % 8 == 7):
      p()
  p('Cache')
  for i, k in enumerate(machine.cache.sets):
    p('Set %d: LRU=%d' % (i, k.lru))
    for j, l in enumerate(k.entries):
      p('\tEntry %d:[(%d,%d,%d)<%s,%s>]' % (j, l.v, l.d, l.tag, bin(l.words[0]), bin(l.words[1])))
  p()
  dataAddr = findDataAddress(machine.memory.instructions)
  p("Data")
  for i, instruction in enumerate(machine.memory.instructions[dataAddr:]):
    if(i % 8 == 0):
      out[0] += '%02d:' % (96 + (dataAddr + i) * 4)
    out[0] += '\t%d' % Word.convert32BitUnsignedToSigned(instruction)
    if(i % 8 == 7):
      p()
  p()
  file.write(out[0])
示例#3
0
def displayDataValue(word, index):
  for i in xrange(31, -1, -1): #decrement value
    print((word & 2**i) >> i, end="", file=target_file)
  print("\t",(index * 4 + 96),"\t" , Word.convert32BitUnsignedToSigned(word), sep = "", file=target_file)