Add and_rm32_r32(0x21) instruction

This commit is contained in:
tuz358
2018-03-06 11:02:27 +09:00
parent 10d45e5c9e
commit a19884aeee
2 changed files with 52 additions and 0 deletions

View File

@@ -25,6 +25,7 @@ void Instructions::init_instructions(){
this->instructions[0x05] = &Instructions::add_eax_imm32;
this->instructions[0x09] = &Instructions::or_rm32_r32;
this->instructions[0x0b] = &Instructions::or_r32_rm32;
this->instructions[0x21] = &Instructions::and_rm32_r32;
this->instructions[0x31] = &Instructions::xor_rm32_r32;
this->instructions[0x40] = &Instructions::inc_eax;
this->instructions[0x41] = &Instructions::inc_ecx;
@@ -305,6 +306,56 @@ void Instructions::or_r32_rm32(){
}
}
void Instructions::and_rm32_r32(){
//printf("and_rm32_r32 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:
// and [M], R
// addr : M
this->eip++;
addr = this->registers[this->M];
// dst : data of [M]
dst = memory.read_uint32(addr);
memory.write_uint32(addr, dst & this->registers[this->R]);
break;
case 1:
// and [M+imm8], R
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);
memory.write_uint32(addr + imm8, dst & this->registers[this->R]);
this->eip++;
break;
case 2:
// and [M+imm32], R
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); // error
memory.write_uint32(addr, dst & this->registers[this->R]);
this->eip += 4;
break;
default:
// case mod == 3
// and M, R
this->eip++;
this->registers[this->M] &= this->registers[this->R];
break;
}
}
void Instructions::xor_rm32_r32(){
//printf("xor_rm32_r32 called.\n");
uint32_t addr, dst, imm32;