Implement lea

This commit is contained in:
2023-07-09 13:02:09 +09:00
parent a82d55c4ce
commit e99e054e24
4 changed files with 12 additions and 2 deletions
+1 -1
View File
@@ -149,7 +149,7 @@ const instruction_t instructions[] = {
{.opcode = 0x8A, .extended = -1, .name = "mov", .mode = {REG8, R_M8, END}, .exec = &mov},
{.opcode = 0x8B, .extended = -1, .name = "mov", .mode = {REG16, R_M16, END}, .exec = &mov},
// {.opcode = 0x8C, .extended = -1, .name = "mov", .mode = {R_M16, sreg, END}, .exec = &mov},
{.opcode = 0x8D, .extended = -1, .name = "lea", .mode = {REG16, R_M16, END}, .exec = NULL},
{.opcode = 0x8D, .extended = -1, .name = "lea", .mode = {REG16, R_M16, END}, .exec = &lea},
// {.opcode = 0x8E, .extended = -1, .name = "mov", .mode = {sreg, R_M16, END}, .exec = &mov},
{.opcode = 0x8F, .extended = -1, .name = "pop", .mode = {R_M16, END}, .exec = NULL},
{.opcode = 0x90, .extended = -1, .name = "xchg ax, ax", .mode = {END}, .exec = NULL},
+1
View File
@@ -8,6 +8,7 @@ void push(const instruction_t *self, state_t *state);
void call(const instruction_t *self, state_t *state);
void jmp(const instruction_t *self, state_t *state);
void int_inst(const instruction_t *self, state_t *state);
void lea(const instruction_t *self, state_t *state);
void sub(const instruction_t *self, state_t *state);
void xor_inst(const instruction_t *self, state_t *state);
+9
View File
@@ -74,3 +74,12 @@ void int_inst(const instruction_t *self, state_t *state)
break;
}
}
void lea(const instruction_t *self, state_t *state)
{
operand_t to = get_operand(self, 0, state);
operand_t memory = get_operand(self, 1, state);
// to = &memory;
write_op(to, memory.ptr - state->memory);
}
+1 -1
View File
@@ -85,7 +85,7 @@ operand_t get_rm_operand(state_t *state, unsigned *imm_idx, bool is16bit)
.ptr = &state->binary[state->pc + state->parse_data.imm_idx],
.type = mod == 0b10 ? BIT16 : BIT8}
);
state->parse_data.imm_idx += mod == 0b10 ? 2 : 1;
*imm_idx += mod == 0b10 ? 2 : 1;
}
operand_t ret = {.ptr = NULL, .type = is16bit ? BIT16 : BIT8};