Add sub_r32_rm32(0x2b) instruction

This commit is contained in:
tuz358
2018-03-06 11:17:44 +09:00
parent 5d317a3ae9
commit 700b19eae7
2 changed files with 52 additions and 0 deletions

View File

@@ -30,6 +30,7 @@ void Instructions::init_instructions(){
this->instructions[0x23] = &Instructions::and_r32_rm32;
this->instructions[0x25] = &Instructions::and_eax_imm32;
this->instructions[0x29] = &Instructions::sub_rm32_r32;
this->instructions[0x2b] = &Instructions::sub_r32_rm32;
this->instructions[0x31] = &Instructions::xor_rm32_r32;
this->instructions[0x40] = &Instructions::inc_eax;
this->instructions[0x41] = &Instructions::inc_ecx;
@@ -473,6 +474,56 @@ void Instructions::sub_rm32_r32(){
}
}
void Instructions::sub_r32_rm32(){
//printf("sub_r32_rm32 called.\n");
uint32_t addr, dst, imm32;
uint8_t imm8;
this->modrm = memory.read_uint8(this->eip);
this->calc_modrm();
switch (this->mod) {
case 0:
// sub R, [M]
// addr : M
this->eip++;
addr = this->registers[this->M];
// dst : data of [M]
dst = memory.read_uint32(addr);
this->registers[this->R] -= dst;
break;
case 1:
// sub R, [M+imm8]
this->eip++;
imm8 = memory.read_uint8(this->eip);
// addr : M
addr = this->registers[this->M];
// dst : data of [M+imm8]
dst = memory.read_uint32(addr + imm8);
this->registers[this->R] -= dst;
this->eip++;
break;
case 2:
// sub R, [M+imm32]
this->eip++;
imm32 = memory.read_uint32(this->eip);
imm32 = swap_endian32(imm32);
// addr : M
addr = this->registers[this->M];
// dst : data of [M+imm32]
dst = memory.read_uint32(addr + imm32);
this->registers[this->R] -= dst;
this->eip += 4;
break;
default:
// case mod == 3
// sub R, M
this->eip++;
this->registers[this->R] -= this->registers[this->M];
break;
}
}
void Instructions::xor_rm32_r32(){
//printf("xor_rm32_r32 called.\n");
uint32_t addr, dst, imm32;