#include #include #include "disasm.h" using namespace boost; std::string disasm::decode(std::string str) { /* we need 0x prefix */ string hex = "0x"; hex.append(str); unsigned int val = lexical_cast(hex); dynamic_bitset<> bits(32,val), opcode(32,val), condition(9), args(32); args = opcode; args.resize(23); opcode >>= 23; condition = opcode; opcode.resize(5); condition >>= 5; condition.resize(4); //cout << "<" << hex << "> is in int " << val << "\t is binary " << bits << " opcode?" << opcode << " condition " << condition << endl; try { Iinstr* instr = decodeOpcode(opcode.to_ulong()); instr->decodeCondition(condition.to_ulong()); instr->loadBits(args); instr->evalInstr(); return instr->toString(); } catch(std::string &e) { cerr << " Error: " << e << endl; } return ""; } Iinstr* disasm::decodeOpcode(short opcode) { auto iter = instrs.find(opcode); if(iter != instrs.end()) { return iter->second; } else { stringstream err; err << "opcode not found" << endl; throw err.str(); } }