j-a

disasm.py

j-a
Feb 26th, 2012
557
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import os
  2. from emu8086 import DisAsm
  3.  
  4. def main(program):
  5.  
  6.     labels = {
  7.                 0x0:'start',
  8.                 0x6:'hlt',
  9.                 0x7:'cont',
  10.                 0x5d:'calltest',
  11.                 0x72:'rettest',
  12.                 0x81:'cont1',
  13.                 0x8f:'ascii_loop',
  14.                 0xa2:'boxloop',
  15.                 0xbb:'cont2',
  16.                 0xc3:'boxloop2',
  17.                 0xe6:'fibloop',
  18.                 0x100:'squareloop',
  19.                 0x11d:'primeloop',
  20.                 0x131:'primeloop_inner',
  21.                 0x13d:'primecont',
  22.                 0x144:'calcsq',
  23.                 0x14a:'calcsqloop',
  24.                 0x151:'calcsqfinish',
  25.                 0x154:'print',
  26.                 0x158:'printloop',
  27.                 0x169:'printchr',
  28.                 0x17c:'printnl',
  29.                 0x180:'printnlloop',
  30.                 0x18a:'printnum',
  31.                 0x198:'numloop_3digit',
  32.                 0x1ab:'numloop_2digit',
  33.                 0x1b6:'numcont_2digit',
  34.                 0x1bd:'numcont_1digit',
  35.                }
  36.  
  37.     def labeled(addr):
  38.         return labels[addr] if addr in labels else hex(addr)
  39.  
  40.     addr = 0
  41.     for instr in DisAsm().instructions(program):
  42.         if addr in labels:
  43.             print "\n{0:>5}:".format(labels[addr])
  44.         print "{0:<10}{1:<10}".format(hex(addr), instr),
  45.         addr += instr.length()
  46.         if (hasattr(instr, 'rel_addr')):
  47.             print "# {0}".format(labeled(instr.rel_addr() + addr))
  48.         else:
  49.             print
  50.  
  51.  
  52. if __name__ == '__main__':
  53.     def program_path():
  54.         return os.path.join(os.path.dirname(__file__), 'codegolf')
  55.     main([ord(c) for c in open(program_path(), 'rb').read()])
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×