Add functions of ModRM

This commit is contained in:
tuz358
2018-03-04 17:29:57 +09:00
parent b8350dcb6d
commit 88cf93a721
2 changed files with 18 additions and 0 deletions

View File

@@ -13,9 +13,13 @@ public:
uint32_t eflags; // EFLAGS register
uint32_t eip; // Instruction pointer
uint8_t modrm, mod, R, M; // ModRM
void (Instructions::*instructions[256])(void);
void init(uint32_t eip, uint32_t esp, Memory memory);
void init_modrm();
void calc_modrm();
void execute_opcode(uint8_t opcode);
void nop();

View File

@@ -14,6 +14,7 @@ void Instructions::init(uint32_t eip, uint32_t esp, Memory memory){
this->memory = memory;
this->init_instructions();
this->init_modrm();
}
void Instructions::init_instructions(){
@@ -23,6 +24,19 @@ void Instructions::init_instructions(){
this->instructions[0xf4] = &Instructions::hlt;
}
void Instructions::init_modrm(){
this->modrm = 0;
this->mod = 0;
this->R = 0;
this->M = 0;
}
void Instructions::calc_modrm(){
this->mod = (this->modrm & 0xc0) >> 6;
this->R = (this->modrm & 0x38) >> 3;
this->M = this->modrm & 0x07;
}
void Instructions::execute_opcode(uint8_t opcode){
(this->*instructions[opcode])();
}