From c00f7378b78ec5545de0af179d1a84acb26b94ee Mon Sep 17 00:00:00 2001 From: tuz358 Date: Sun, 18 Mar 2018 15:51:14 +0900 Subject: [PATCH] Add sub_rm32_imm(0x81,0x83) instruction --- include/instructions.h | 1 + instructions.cpp | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/include/instructions.h b/include/instructions.h index 8e81bff..1fa0e79 100644 --- a/include/instructions.h +++ b/include/instructions.h @@ -137,5 +137,6 @@ public: void adc_rm32_imm(int imm_flag); void sbb_rm32_imm(int imm_flag); void and_rm32_imm(int imm_flag); + void sub_rm32_imm(int imm_flag); void cmp_rm32_imm8(); }; diff --git a/instructions.cpp b/instructions.cpp index a5dc016..e969b35 100644 --- a/instructions.cpp +++ b/instructions.cpp @@ -487,7 +487,7 @@ void Instructions::opcode_81(){ and_rm32_imm(IMM32); break; case 5: - // TODO: sub_rm32_imm32(); + sub_rm32_imm(IMM32); break; case 6: // TODO: xor_rm32_imm32(); @@ -523,7 +523,7 @@ void Instructions::opcode_83(){ and_rm32_imm(IMM8); break; case 5: - // TODO: sub_rm32_imm8(); + sub_rm32_imm(IMM8); break; case 6: // TODO: xor_rm32_imm8(); @@ -874,6 +874,24 @@ void Instructions::and_rm32_imm(int imm_flag){ this->eip++; } +void Instructions::sub_rm32_imm(int imm_flag){ + //printf("sub_rm32_imm called.\n"); + + this->eip++; + + if(imm_flag == IMM8){ + uint8_t imm8 = memory.read_uint8(this->eip); + this->registers[this->M] -= imm8; + } else if(imm_flag == IMM32){ + uint32_t imm32 = memory.read_uint32(this->eip); + imm32 = swap_endian32(imm32); + this->registers[this->M] -= imm32; + } else { + } + + this->eip++; +} + void Instructions::cmp_rm32_imm8(){ //printf("cmp_rm32_imm8 called.\n");