if (opcode&(1<<10)){ dest = addStr(dest, "#0x"); dest = addHex(dest, 0, (opcode>>6)&7); } else { dest = addStr(dest, regs[(opcode>>6)&7]); }
dest = addStr(dest, "#0x"); dest = addHex(dest, 0, (opcode>>6)&7);
int disThumb(u32 offset, char *dest, int flags){  u32 opcode = debuggerReadHalfWord(offset);          const Opcodes *sp = thumbOpcodes;  int ret = 2;  while( sp->cval != (opcode & sp->mask) )    sp++;          if (flags&DIS_VIEW_ADDRESS){    dest = addHex(dest, 32, offset);    *dest++ = ' ';  }  if (flags&DIS_VIEW_CODE){    dest = addHex(dest, 16, opcode);    *dest++ = ' ';  }          char *src = sp->mnemonic;  while (*src){    if (*src!='%')      *dest++ = *src++;    else {      src++;      switch (*src){      case 'r':        src++;        dest = addStr(dest, regs[(opcode>>(*src-'0'))&7]);        break;      case 'o':        dest = addStr(dest, "#0x");        {          int val = (opcode>>6)&0x1f;          dest = addHex(dest, 8, val);        }        break;      case 'p':        dest = addStr(dest, "#0x");        {          int val = (opcode>>6)&0x1f;          if (!(opcode&(1<<12)))            val <<= 2;          dest = addHex(dest, 0, val);        }        break;      case 'e':        dest = addStr(dest, "#0x");        dest = addHex(dest, 0, ((opcode>>6)&0x1f)<<1);        break;      case 'i':        if (opcode&(1<<10)){          dest = addStr(dest, "#0x");          dest = addHex(dest, 0, (opcode>>6)&7);        } else {          dest = addStr(dest, regs[(opcode>>6)&7]);        }        break;      case 'h':        {          src++;          int reg = (opcode>>(*src-'0'))&7;          src++;          if (opcode&(1<<(*src-'0')))            reg += 8;          dest = addStr(dest, regs[reg]);        }        break;      case 'O':        dest = addStr(dest, "#0x");        dest = addHex(dest, 0, (opcode&0xff));        break;      case 'I':        *dest++ = '$';        dest = addHex(dest, 32, (offset&0xfffffffc)+4+((opcode&0xff)<<2));        break;      case 'J':        {          u32 value = debuggerReadMemory((offset&0xfffffffc)+4+                                         ((opcode & 0xff)<<2));          *dest++ = '$';          dest = addHex(dest, 32, value);          char *s = elfGetAddressSymbol(value);          if(*s) {            *dest++ = ' ';            dest = addStr(dest, s);          }        }        break;      case 'K':        {          u32 value = (offset&0xfffffffc)+4+((opcode & 0xff)<<2);          *dest++ = '$';          dest = addHex(dest, 32, value);          char *s = elfGetAddressSymbol(value);          if(*s) {            *dest++ = ' ';            dest = addStr(dest, s);          }                  }        break;      case 'b':        if (opcode&(1<<10))          *dest++ = 'b';        break;      case 'B':        if (opcode&(1<<12))          *dest++ = 'b';        break;      case 'w':        dest = addStr(dest, "#0x");        dest = addHex(dest, 0, (opcode&0xff)<<2);        break;      case 'W':        *dest++ = '$';        {          int add = opcode&0xff;          if (add&0x80)            add |= 0xffffff00;          dest = addHex(dest, 32, (offset&0xfffffffe)+4+(add<<1));        }        break;      case 'c':        dest = addStr(dest, conditions[(opcode>>8)&15]);        break;      case 's':        if (opcode&(1<<7))          *dest++ = '-';        dest = addStr(dest, "#0x");        dest = addHex(dest, 0, (opcode&0x7f)<<2);        break;      case 'l':        {          int rlst = opcode&0xff;          int msk = 0;          int not_first = 0;          while (msk<8){            if (rlst&(1<<msk)){              int fr = msk;              while (rlst&(1<<msk))                msk++;              int to = msk-1;              if (not_first)                *dest++ = ',';              dest = addStr(dest, regs[fr]);              if (fr!=to){                if (fr==to-1)                  *dest++ = ',';                else                  *dest++ = '-';                dest = addStr(dest, regs[to]);              }              not_first = 1;            } else              msk++;          }        }        break;      case 'm':        *dest++ = '$';        dest = addHex(dest, 8, opcode&0xff);        break;      case 'Z':        *dest++ = '$';        dest = addHex(dest, 16, (opcode&0x7ff)<<1);        break;      case 'a':        *dest++ = '$';        {          int add = opcode&0x07ff;          if (add&0x400)            add |= 0xfffff800;          add <<= 1;          dest = addHex(dest, 32, offset+4+add);        }        break;      case 'A':        {          int nopcode = debuggerReadHalfWord(offset+2);          int add = opcode&0x7ff;          if (add&0x400)            add |= 0xfff800;          add = (add<<12)|((nopcode&0x7ff)<<1);          *dest++ = '$';          dest = addHex(dest,32, offset+4+add);          char *s = elfGetAddressSymbol(offset+4+add);          if(*s) {            *dest++ = ' ';            *dest++ = '(';            dest = addStr(dest, s);            *dest++ = ')';          }          ret = 4;        }        break;      }      src++;    }  }  *dest++ = 0;  return ret;}