diff --git a/include/instructions.h b/include/instructions.h index 1493371..581752e 100644 --- a/include/instructions.h +++ b/include/instructions.h @@ -91,6 +91,7 @@ public: void mov_ebp_imm32(); // 0xbd void mov_esi_imm32(); // 0xbe void mov_edi_imm32(); // 0xbf + void call_imm32(); // 0xe8 void jmp_imm8(); // 0xeb void hlt(); // 0xf4 void opcode_ff(); // 0xff diff --git a/instructions.cpp b/instructions.cpp index c5f8889..cb730e4 100644 --- a/instructions.cpp +++ b/instructions.cpp @@ -87,6 +87,7 @@ void Instructions::init_instructions(){ this->instructions[0xbd] = &Instructions::mov_ebp_imm32; this->instructions[0xbe] = &Instructions::mov_esi_imm32; this->instructions[0xbf] = &Instructions::mov_edi_imm32; + this->instructions[0xe8] = &Instructions::call_imm32; this->instructions[0xeb] = &Instructions::jmp_imm8; this->instructions[0xf4] = &Instructions::hlt; this->instructions[0xff] = &Instructions::opcode_ff; @@ -1062,6 +1063,19 @@ void Instructions::mov_edi_imm32(){ this->eip += 4; } +void Instructions::call_imm32(){ + //printf("call_imm32 called.\n"); + + int32_t imm32 = memory.read_int32(this->eip); + imm32 = (int32_t)swap_endian32((uint32_t)imm32); + // push eip + this->registers[4] -= 4; // esp -= 4 + memory.write_uint32(this->registers[4], this->eip); + // jmp imm32 + this->eip += imm32; + this->eip += 4; +} + void Instructions::jmp_imm8() { //printf("jmp_imm8 called.\n");