From 2b42720df0601947b974ffd2e8aed03e6e0213f0 Mon Sep 17 00:00:00 2001 From: tuz358 Date: Mon, 19 Mar 2018 00:45:35 +0900 Subject: [PATCH] Add cmp_rm32_imm(0x81,0x83) instruction --- include/instructions.h | 2 +- instructions.cpp | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/include/instructions.h b/include/instructions.h index 7a1918c..e46ee93 100644 --- a/include/instructions.h +++ b/include/instructions.h @@ -139,5 +139,5 @@ public: void and_rm32_imm(int imm_flag); void sub_rm32_imm(int imm_flag); void xor_rm32_imm(int imm_flag); - void cmp_rm32_imm8(); + void cmp_rm32_imm(int imm_flag); }; diff --git a/instructions.cpp b/instructions.cpp index 393763d..ca7bd67 100644 --- a/instructions.cpp +++ b/instructions.cpp @@ -493,7 +493,7 @@ void Instructions::opcode_81(){ xor_rm32_imm(IMM32); break; case 7: - // TODO: cmp_rm32_imm8(); + cmp_rm32_imm(IMM32); break; default: break; @@ -514,7 +514,7 @@ void Instructions::opcode_83(){ case 4: and_rm32_imm(IMM8); break; case 5: sub_rm32_imm(IMM8); break; case 6: xor_rm32_imm(IMM8); break; - case 7: cmp_rm32_imm8(); break; + case 7: cmp_rm32_imm(IMM8); break; default: break; } } @@ -893,15 +893,20 @@ void Instructions::xor_rm32_imm(int imm_flag){ this->eip++; } -void Instructions::cmp_rm32_imm8(){ - //printf("cmp_rm32_imm8 called.\n"); +void Instructions::cmp_rm32_imm(int imm_flag){ + //printf("cmp_rm32_imm called.\n"); this->eip++; - uint8_t imm8 = memory.read_uint8(this->eip); - //printf("imm8: 0x%08x (%d)\n", imm8, imm8); - uint32_t result = this->registers[this->M] - imm8; - set_flag(!result, ZF); + if(imm_flag == IMM8){ + uint8_t imm8 = memory.read_uint8(this->eip); + set_flag(!(this->registers[this->M] - imm8), ZF); + } else if(imm_flag == IMM32){ + uint32_t imm32 = memory.read_uint32(this->eip); + imm32 = swap_endian32(imm32); + set_flag(!(this->registers[this->M] - imm32), ZF); + } else { + } this->eip++; }