Fix sub instruction

This commit is contained in:
2023-07-07 16:22:11 +09:00
parent be7cba2f35
commit 56f78ce96f
+8 -15
View File
@@ -6,25 +6,18 @@ void sub(const instruction_t *self, state_t *state)
{
void *from = get_operand(self, 0, state);
void *to = get_operand(self, 1, state);
bool is16bit = is_operand_wide(self, 0);
unsigned old;
unsigned value;
unsigned old = is_operand_wide(self, 0) ? *(uint16_t *)from : *(uint8_t *)from;
unsigned minus = is_operand_wide(self, 1) ? *(uint16_t *)to : *(uint8_t *)to;
unsigned value = old - minus;
if (is16bit) {
old = *(uint16_t *)from;
value = old - *(uint16_t *)to;
if (is_operand_wide(self, 0))
*(uint16_t *)from = value;
} else {
old = *(uint8_t *)from;
value = old - *(uint8_t *)to;
else
*(uint8_t *)from = value;
}
unsigned neg_mask = is16bit ? 0x8000 : 0x80;
state->of = value != (is16bit ? *(uint16_t *)from : *(uint8_t *)from);
state->cf = old < (is16bit ? *(uint16_t *)to : *(uint8_t *)to);
state->sf = value & neg_mask;
state->of = value != (is_operand_wide(self, 0) ? *(uint16_t *)from : *(uint8_t *)from);
state->cf = old < minus;
state->sf = value & (is_operand_wide(self, 0) ? 0x8000 : 0x80);
state->zf = value == 0;
printf("Old %x - %x = %x\n", old, *(uint16_t *)to, *(uint16_t *)from);
// TODO: Set AF and PF
}