diff --git a/src/instructions.c b/src/instructions.c index 1c362ec..91fb36c 100644 --- a/src/instructions.c +++ b/src/instructions.c @@ -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}, diff --git a/src/instructions.h b/src/instructions.h index 467f494..2f6b1f3 100644 --- a/src/instructions.h +++ b/src/instructions.h @@ -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); diff --git a/src/instructions/memory.c b/src/instructions/memory.c index 9bab316..c4372e1 100644 --- a/src/instructions/memory.c +++ b/src/instructions/memory.c @@ -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); +} diff --git a/src/interpretor.c b/src/interpretor.c index 94e35bc..98e4e4e 100644 --- a/src/interpretor.c +++ b/src/interpretor.c @@ -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};