Updated decode_register to use flat array instead of branches
This commit is contained in:
parent
d683951f67
commit
d4733b7be7
@ -96,64 +96,23 @@ uint16_t decode_mode(uint16_t instruction) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void decode_register(uint16_t instruction, bool word, char *dest) {
|
void decode_register(uint16_t instruction, bool word, char *dest) {
|
||||||
uint16_t reg_mask = 0x07;
|
static uint16_t reg_mask = 0x07;
|
||||||
|
|
||||||
switch (instruction & reg_mask) {
|
// clang-format off
|
||||||
case 0x00:
|
static const char *table[16] = {
|
||||||
if (word) {
|
"al", "ax",
|
||||||
strcpy(dest, "ax");
|
"cl", "cx",
|
||||||
} else {
|
"dl", "dx",
|
||||||
strcpy(dest, "al");
|
"bl", "bx",
|
||||||
}
|
"ah", "sp",
|
||||||
break;
|
"ch", "bp",
|
||||||
case 0x01:
|
"dh", "si",
|
||||||
if (word) {
|
"bh", "di"
|
||||||
strcpy(dest, "cx");
|
};
|
||||||
} else {
|
// clang-format on
|
||||||
strcpy(dest, "cl");
|
|
||||||
}
|
uint16_t offset = instruction & reg_mask;
|
||||||
break;
|
|
||||||
case 0x02:
|
// Multiply offset by 2 since each row has 2 columns
|
||||||
if (word) {
|
strcpy(dest, table[offset * 2 + (uint16_t)word]);
|
||||||
strcpy(dest, "dx");
|
|
||||||
} else {
|
|
||||||
strcpy(dest, "dl");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 0x03:
|
|
||||||
if (word) {
|
|
||||||
strcpy(dest, "bx");
|
|
||||||
} else {
|
|
||||||
strcpy(dest, "bl");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 0x04:
|
|
||||||
if (word) {
|
|
||||||
strcpy(dest, "sp");
|
|
||||||
} else {
|
|
||||||
strcpy(dest, "ah");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 0x05:
|
|
||||||
if (word) {
|
|
||||||
strcpy(dest, "bp");
|
|
||||||
} else {
|
|
||||||
strcpy(dest, "ch");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 0x06:
|
|
||||||
if (word) {
|
|
||||||
strcpy(dest, "si");
|
|
||||||
} else {
|
|
||||||
strcpy(dest, "dh");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 0x07:
|
|
||||||
if (word) {
|
|
||||||
strcpy(dest, "di");
|
|
||||||
} else {
|
|
||||||
strcpy(dest, "bh");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user