mirror of
https://github.com/tuz358/cpu-emulator.git
synced 2025-12-16 20:17:04 +03:00
Add push_e**(0x50~0x57) instruction
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
void Emulator::init(size_t memorysize, FILE *bin){
|
||||
memory.init(memorysize);
|
||||
memory.load_binary(bin);
|
||||
instructions.init(0, (int)memorysize/2, memory);
|
||||
instructions.init(0, (int)memorysize, memory);
|
||||
}
|
||||
|
||||
void Emulator::free(){
|
||||
@@ -20,6 +20,10 @@ void Emulator::dump_registers(){
|
||||
printf("ecx = 0x%08x (%d)\n", instructions.registers[1], instructions.registers[1]);
|
||||
printf("edx = 0x%08x (%d)\n", instructions.registers[2], instructions.registers[2]);
|
||||
printf("ebx = 0x%08x (%d)\n", instructions.registers[3], instructions.registers[3]);
|
||||
printf("esp = 0x%08x (%d)\n", instructions.registers[4], instructions.registers[4]);
|
||||
printf("ebp = 0x%08x (%d)\n", instructions.registers[5], instructions.registers[5]);
|
||||
printf("esi = 0x%08x (%d)\n", instructions.registers[6], instructions.registers[6]);
|
||||
printf("edi = 0x%08x (%d)\n", instructions.registers[7], instructions.registers[7]);
|
||||
printf("eip = 0x%08x (%d)\n", instructions.eip, instructions.eip);
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,14 @@ public:
|
||||
void dec_ebp(); // 0x4d
|
||||
void dec_esi(); // 0x4e
|
||||
void dec_edi(); // 0x4f
|
||||
void push_eax(); // 0x50
|
||||
void push_ecx(); // 0x51
|
||||
void push_edx(); // 0x52
|
||||
void push_ebx(); // 0x53
|
||||
void push_esp(); // 0x54
|
||||
void push_ebp(); // 0x55
|
||||
void push_esi(); // 0x56
|
||||
void push_edi(); // 0x57
|
||||
void jne_imm8(); // 0x75
|
||||
void opcode_83(); // 0x83
|
||||
void mov_rm32_r32(); // 0x89
|
||||
|
||||
@@ -38,6 +38,14 @@ void Instructions::init_instructions(){
|
||||
this->instructions[0x4d] = &Instructions::dec_ebp;
|
||||
this->instructions[0x4e] = &Instructions::dec_esi;
|
||||
this->instructions[0x4f] = &Instructions::dec_edi;
|
||||
this->instructions[0x50] = &Instructions::push_eax;
|
||||
this->instructions[0x51] = &Instructions::push_ecx;
|
||||
this->instructions[0x52] = &Instructions::push_edx;
|
||||
this->instructions[0x53] = &Instructions::push_ebx;
|
||||
this->instructions[0x54] = &Instructions::push_esp;
|
||||
this->instructions[0x55] = &Instructions::push_ebp;
|
||||
this->instructions[0x56] = &Instructions::push_esi;
|
||||
this->instructions[0x57] = &Instructions::push_edi;
|
||||
this->instructions[0x75] = &Instructions::jne_imm8;
|
||||
this->instructions[0x83] = &Instructions::opcode_83;
|
||||
this->instructions[0x89] = &Instructions::mov_rm32_r32;
|
||||
@@ -248,6 +256,54 @@ void Instructions::dec_esi(){
|
||||
this->registers[6]--;
|
||||
}
|
||||
|
||||
void Instructions::push_eax(){
|
||||
//printf("push_eax called.\n");
|
||||
this->registers[4] -= 4;
|
||||
memory.write_uint32(this->registers[4], this->registers[0]);
|
||||
}
|
||||
|
||||
void Instructions::push_ecx(){
|
||||
//printf("push_ecx called.\n");
|
||||
this->registers[4] -= 4;
|
||||
memory.write_uint32(this->registers[4], this->registers[1]);
|
||||
}
|
||||
|
||||
void Instructions::push_edx(){
|
||||
//printf("push_edx called.\n");
|
||||
this->registers[4] -= 4;
|
||||
memory.write_uint32(this->registers[4], this->registers[2]);
|
||||
}
|
||||
|
||||
void Instructions::push_ebx(){
|
||||
//printf("push_ebx called.\n");
|
||||
this->registers[4] -= 4;
|
||||
memory.write_uint32(this->registers[4], this->registers[3]);
|
||||
}
|
||||
|
||||
void Instructions::push_esp(){
|
||||
//printf("push_esp called.\n");
|
||||
this->registers[4] -= 4;
|
||||
memory.write_uint32(this->registers[4], this->registers[4]);
|
||||
}
|
||||
|
||||
void Instructions::push_ebp(){
|
||||
//printf("push_ebp called.\n");
|
||||
this->registers[4] -= 4;
|
||||
memory.write_uint32(this->registers[4], this->registers[5]);
|
||||
}
|
||||
|
||||
void Instructions::push_esi(){
|
||||
//printf("push_esi called.\n");
|
||||
this->registers[4] -= 4;
|
||||
memory.write_uint32(this->registers[4], this->registers[6]);
|
||||
}
|
||||
|
||||
void Instructions::push_edi(){
|
||||
//printf("push_edi called.\n");
|
||||
this->registers[4] -= 4;
|
||||
memory.write_uint32(this->registers[4], this->registers[7]);
|
||||
}
|
||||
|
||||
void Instructions::dec_edi(){
|
||||
//printf("dec_edi called.\n");
|
||||
this->registers[7]--;
|
||||
|
||||
Reference in New Issue
Block a user