29. Instructions
Instruction[] instructions = new Instruction[256];
instructions[0x00] = new AddRM8R8();
instructions[0x01] = new AddRMXRX();
instructions[0x02] = new AddR8RM8();
instructions[0x03] = new AddRXRMX();
instructions[0x04] = new AddALImm8();
29
30. 命令実行命令実装編 1/3
public class MoveALImm8 implements Instruction{
public void exeucte(VM vm){
int imm = vm.getCode8(1);
vm.setRegister8Low(EAX, imm);
vm.addEIP(2);
}
}
30
31. 命令実行命令実装編 2/3
public class MoveR8RM8 implements …
public void exeucte(VM vm){
int modrm = vm.getCode8(1);
int mod = modrm >> 6;
int register = (modrm >> 3) & 0x07;
int rm = modrm & 0x07;
/* 処理 */
31
32. 命令実行命令実装編 3/3
public class MoveR8RM8 implements …
public void execute(VM vm){
ModRM modrm = vm.getModRM();
int value = modrm.getRMValue8();
modrm.setRegister8(value);
vm.addEIP(2);
}
}
32
34. ModR/M による命令分岐の実装
1/2
public class ExtD0 implements Instruction{
private Instruction[] instructions;
public ExtD0(){
instructions = new Instruction[8];
instructions[0] = new ROLRM8();
instructions[1] = new RORRM8();
}
34
35. ModR/M による命令分岐の実装
2/2
public void execute(VM vm){
int code =
vm.getModRM(false).getOpecode();
instruction = instructions[code];
instruction.execute(vm)
}
35
36. オペコードが多バイトの場合
public class Ext0F implements Instruction{
private Instruction[] instructions;
private Instruction instruction;
public Ext0F(){
instructions = new Instruction[256];
instructions[0x00] = new Descriptor0();
instructions[0x01] = new Descriptor();
instructions[0x20] = new MoveR32CRX();
36