1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
| opcode = [ 0x00000008, 0x00000001, 0x00000000, 0x00000008, 0x00000003, 0x00000046, 0x0000000E, 0x00000015, 0x0000000A, 0x00000001, 0x00000009, 0x00000002, 0x0000000B, 0x0000000A, 0x00000001, 0x0000000A, 0x00000002, 0x00000009, 0x00000001, 0x00000011, 0x00000001, 0x0000000D, 0x00000001, 0x00000003, 0x0000000F, 0x00000008, 0x00000008, 0x00000001, 0x00000000, 0x00000008, 0x00000003, 0x00000047, 0x0000000E, 0x00000046, 0x0000000A, 0x00000001, 0x0000001A, 0x00000002, 0x00000006, 0x0000001D, 0x00000001, 0x00000004, 0x00000014, 0x00000002, 0x00000001, 0x00000019, 0x00000001, 0x00000002, 0x0000001B, 0x00000001, 0x00000001, 0x0000001D, 0x00000001, 0x0000006E, 0x00000013, 0x00000001, 0x00000063, 0x00000015, 0x00000001, 0x00000074, 0x00000013, 0x00000001, 0x00000066, 0x0000001C, 0x00000002, 0x00000001, 0x00000009, 0x00000001, 0x00000011, 0x00000001, 0x0000000D, 0x00000001, 0x00000003, 0x0000000F, 0x00000022, 0x00000064 ]
def disasm(i, c): if c == 8: print ("_%02X:\t" % i + "mov R{} {}".format(opcode[i+1]-1,opcode[i+2])) i=i+3 elif c == 9: print ("_%02X:\t" % i + "pop R{}".format(opcode[i+1]-1)) i=i+2 elif c == 0xa: print ("_%02X:\t" % i + "push R{}".format(opcode[i+1]-1)) i=i+2 elif c == 0xb: print ("_%02X:\t" % i + "R0=getchar()") i=i+1 elif c == 0xc: print ("_%02X:\t" % i + "R0=putchar()") i=i+1 elif c == 0xd: print("_%02X:\t" % i + "cmp R{} R{}".format(opcode[i+1]-1,opcode[i+2]-1)) print(" jnz {}".format(i+3)) print(" mov a, 80") i=i+3 elif c == 0xe: print ("_%02X:\t" % i + "jmp {}".format(opcode[i+1])) i=i+2 elif c == 0xf: print("_%02X:\t" % i +"and a, 80") print(" test a a") print(" jnz {}".format(opcode[i+1])) i+=2 elif c == 0x10: print("_%02X:\t" % i +"and a, 80") print(" test a a") print(" jz {}".format(opcode[i+1])) i+=2 elif c == 0x11: print ("_%02X:\t" % i + "inc R{}".format(opcode[i+1]-1)) i=i+2 elif c == 0x12: print ("_%02X:\t" % i + "dec R{}".format(opcode[i+1]-1)) i=i+2 elif c == 0x13: print ("_%02X:\t" % i + "add R{} {}".format(opcode[i+1]-1,opcode[i+2])) i=i+3 elif c == 0x14: print ("_%02X:\t" % i + "sub R{} R{}".format(opcode[i+1]-1,opcode[i+2]-1)) i=i+3 elif c == 0x15: print ("_%02X:\t" % i + "xor R{} {}".format(opcode[i+1]-1,opcode[i+2])) i=i+3 elif c == 0x16: print ("_%02X:\t" % i + "and R{} R{}".format(opcode[i+1]-1,opcode[i+2]-1)) i=i+3 elif c == 0x17: print("_%02X:\t" % i + "or R{} R{}".format(opcode[i+1]-1,opcode[i+2]-1)) i=i+3 elif c == 0x19: print("_%02X:\t" % i + "mov R{} R{}".format(opcode[i+1]-1,opcode[i+2]-1)) i=i+3 elif c == 0x1A: print("_%02X:\t" % i + "mov R{} R{}".format(opcode[i+1]-1,opcode[i+2]-1)) i=i+3 elif c == 0x1B: print("_%02X:\t" % i + "mov R{} [R{}]".format(opcode[i+1]-1,opcode[i+2]-1)) i=i+3 elif c == 0x1C: print("_%02X:\t" % i + "mov [R{}] R{}".format(opcode[i+1]-1,opcode[i+2]-1)) i=i+3 elif c == 0x1D: print ("_%02X:\t" % i + "mul R{} {}".format(opcode[i+1]-1,opcode[i+2])) i=i+3 return i i=0 while(i<len(opcode)-1): i=disasm(i,opcode[i])
|