Print immediate byte data in 2-digits hex

This commit is contained in:
Tadashi G. Takaoka 2018-04-06 00:12:09 +09:00
parent b294df8cc0
commit e5e3dd13eb
2 changed files with 15 additions and 8 deletions

View File

@ -90,10 +90,12 @@ static const char *reg_name(const msp430_reg_t reg)
return buf; return buf;
} }
static int format_addr(msp430_amode_t amode, address_t addr) static int format_addr(msp430_amode_t amode, address_t addr,
msp430_dsize_t dsize)
{ {
char name[MAX_SYMBOL_LENGTH]; char name[MAX_SYMBOL_LENGTH];
const char *prefix = ""; const char *prefix = "";
int print_flags = PRINT_ADDRESS_EXACT;
switch (amode) { switch (amode) {
case MSP430_AMODE_REGISTER: case MSP430_AMODE_REGISTER:
@ -103,6 +105,8 @@ static int format_addr(msp430_amode_t amode, address_t addr)
case MSP430_AMODE_IMMEDIATE: case MSP430_AMODE_IMMEDIATE:
prefix = "#"; prefix = "#";
if (dsize == MSP430_DSIZE_BYTE)
print_flags |= PRINT_BYTE_DATA;
case MSP430_AMODE_INDEXED: case MSP430_AMODE_INDEXED:
break; break;
@ -114,7 +118,7 @@ static int format_addr(msp430_amode_t amode, address_t addr)
break; break;
} }
print_address(addr, name, sizeof(name), PRINT_ADDRESS_EXACT); print_address(addr, name, sizeof(name), print_flags);
return printc("%s\x1b[1m%s\x1b[0m", prefix, name); return printc("%s\x1b[1m%s\x1b[0m", prefix, name);
} }
@ -153,11 +157,11 @@ static int format_reg(msp430_amode_t amode, msp430_reg_t reg)
* Returns the number of characters printed. * Returns the number of characters printed.
*/ */
static int format_operand(msp430_amode_t amode, address_t addr, static int format_operand(msp430_amode_t amode, address_t addr,
msp430_reg_t reg) msp430_reg_t reg, msp430_dsize_t dsize)
{ {
int len = 0; int len = 0;
len += format_addr(amode, addr); len += format_addr(amode, addr, dsize);
len += format_reg(amode, reg); len += format_reg(amode, reg);
return len; return len;
@ -176,7 +180,8 @@ static int dis_format(const struct msp430_instruction *insn)
if (insn->itype == MSP430_ITYPE_DOUBLE) { if (insn->itype == MSP430_ITYPE_DOUBLE) {
len += format_operand(insn->src_mode, len += format_operand(insn->src_mode,
insn->src_addr, insn->src_addr,
insn->src_reg); insn->src_reg,
insn->dsize);
len += printc(","); len += printc(",");
while (len < 15) while (len < 15)
@ -188,7 +193,8 @@ static int dis_format(const struct msp430_instruction *insn)
if (insn->itype != MSP430_ITYPE_NOARG) if (insn->itype != MSP430_ITYPE_NOARG)
len += format_operand(insn->dst_mode, len += format_operand(insn->dst_mode,
insn->dst_addr, insn->dst_addr,
insn->dst_reg); insn->dst_reg,
insn->dsize);
/* Repetition count */ /* Repetition count */
if (insn->rep_register) if (insn->rep_register)
@ -352,7 +358,7 @@ int print_address(address_t addr, char *out, int max_len,
return 1; return 1;
} }
snprintf(out, max_len, "0x%04x", addr); snprintf(out, max_len, (f & PRINT_BYTE_DATA) ? "0x%02x" : "0x%04x", addr);
return 0; return 0;
} }

View File

@ -38,7 +38,8 @@ void show_regs(const address_t *regs);
* Returns non-zero if the result is of the form sym+0x0offset. * Returns non-zero if the result is of the form sym+0x0offset.
*/ */
typedef enum { typedef enum {
PRINT_ADDRESS_EXACT = 0x01 PRINT_ADDRESS_EXACT = 0x01,
PRINT_BYTE_DATA = 0x02
} print_address_flags_t; } print_address_flags_t;
int print_address(address_t addr, char *buf, int max_len, int print_address(address_t addr, char *buf, int max_len,