fix(interpreter): fix mov AX0b instruction

Should not be imm, but a memoryindex
This commit is contained in:
2025-07-24 11:43:30 +09:00
parent 4cc97cffbf
commit 2cb50b5908
4 changed files with 12 additions and 9 deletions

View File

@@ -762,8 +762,8 @@ impl Disassembler {
0x9E => Mnemonic::SAHF,
0x9F => Mnemonic::LAHF,
0xA0 => Mnemonic::MOV_AL0b(self.parse_byte()?),
0xA1 => Mnemonic::MOV_AX0v(self.parse_word()?),
0xA0 => Mnemonic::MOV_AL0b(self.parse_byte()?.into()),
0xA1 => Mnemonic::MOV_AX0v(self.parse_word()?.into()),
0xA2 => Mnemonic::MOV_0bAL(self.parse_byte()?),
0xA3 => Mnemonic::MOV_0vAX(self.parse_word()?),
0xA4 => Mnemonic::MOVSB,

View File

@@ -217,8 +217,8 @@ pub enum Mnemonic {
MOV_Ib(ModRmTarget, Byte),
MOV_Iv(ModRmTarget, Word),
MOV_AL0b(Byte),
MOV_AX0v(Word),
MOV_AL0b(MemoryIndex),
MOV_AX0v(MemoryIndex),
MOV_0bAL(Byte),
MOV_0vAX(Word),
@@ -511,8 +511,8 @@ impl fmt::Display for Mnemonic {
ModRmTarget::Register(_) => write!(f, "mov word {target}, {word:#04x}"),
},
Self::MOV_AL0b(byte) => write!(f, "mov {}, {byte:#04x}", Register::AL),
Self::MOV_AX0v(word) => write!(f, "mov {}, {word:#04x}", Register::AX),
Self::MOV_AL0b(idx) => write!(f, "mov {}, {idx}", Register::AL),
Self::MOV_AX0v(idx) => write!(f, "mov {}, {idx}", Register::AX),
Self::MOV_0bAL(byte) => write!(f, "mov {byte:#04x}, {}", Register::AL),
Self::MOV_0vAX(word) => write!(f, "mov {word:#04x}, {}", Register::AX),

View File

@@ -412,7 +412,8 @@ impl Computer {
let factor = match segment_selector {
crate::register::SegmentRegister::DS => self.sregs.ds * 16,
crate::register::SegmentRegister::SS => self.sregs.ss * 16,
_ => 0,
crate::register::SegmentRegister::ES => self.sregs.es * 16,
crate::register::SegmentRegister::CS => self.sregs.cs * 16,
};
(ImmediateOperand::from(factor) + base + index + disp).into()
}

View File

@@ -564,8 +564,10 @@ impl Interpreter {
Mnemonic::MOV_Ib(target, val) => self.computer.write_modrm(target, val.into())?,
Mnemonic::MOV_Iv(target, val) => self.computer.write_modrm(target, val.into())?,
Mnemonic::MOV_AL0b(val) => self.computer.regs.ax.lower = val,
Mnemonic::MOV_AX0v(val) => self.computer.regs.ax.write(val),
Mnemonic::MOV_AL0b(idx) => {
self.computer.regs.ax.lower = self.computer.read(idx)? as Byte
}
Mnemonic::MOV_AX0v(idx) => self.computer.regs.ax.write(self.computer.read(idx)?),
Mnemonic::MOV_0bAL(b) => self
.computer
.write(self.computer.regs.ax.lower.into(), b.into())?,