mirror of
https://github.com/tuz358/cpu-emulator.git
synced 2025-12-19 05:24:35 +03:00
Add xor_rm32_r32(0x31) instruction
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "memory.h"
|
||||
#include "utils.h"
|
||||
|
||||
class Instructions{
|
||||
private:
|
||||
@@ -22,6 +23,7 @@ public:
|
||||
void calc_modrm();
|
||||
void execute_opcode(uint8_t opcode);
|
||||
|
||||
void nop();
|
||||
void hlt();
|
||||
void xor_rm32_r32(); // 0x31
|
||||
void nop(); // 0x90
|
||||
void hlt(); // 0xf4
|
||||
};
|
||||
|
||||
@@ -20,6 +20,7 @@ void Instructions::init(uint32_t eip, uint32_t esp, Memory memory){
|
||||
void Instructions::init_instructions(){
|
||||
memset(this->instructions, 0, sizeof(this->instructions));
|
||||
|
||||
this->instructions[0x31] = &Instructions::xor_rm32_r32;
|
||||
this->instructions[0x90] = &Instructions::nop;
|
||||
this->instructions[0xf4] = &Instructions::hlt;
|
||||
}
|
||||
@@ -41,6 +42,55 @@ void Instructions::execute_opcode(uint8_t opcode){
|
||||
(this->*instructions[opcode])();
|
||||
}
|
||||
|
||||
void Instructions::xor_rm32_r32(){
|
||||
printf("xor_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:
|
||||
// xor [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:
|
||||
// xor [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]);
|
||||
break;
|
||||
case 2:
|
||||
// xor [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);
|
||||
memory.write_uint32(addr, dst ^ this->registers[this->R]);
|
||||
this->eip += 4;
|
||||
break;
|
||||
default:
|
||||
// case mod == 3
|
||||
// xor M, R
|
||||
this->eip++;
|
||||
this->registers[this->M] ^= this->registers[this->R];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Instructions::nop(){
|
||||
printf("nop called.\n");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user