fix(interpreter): always read word from memory

It's not possible to know if a word or byte is requested, or rather
it would be a pain to retrieve that information.
It is much easier to just read a full word and then discard the top
half, if just a byte is needed.
This commit is contained in:
2025-06-17 12:00:56 +09:00
parent 200640447b
commit 7f4d79d840
2 changed files with 34 additions and 57 deletions

View File

@@ -93,24 +93,24 @@ impl Register {
crate::register::Register::SP => self.sp = Word::from_le_bytes([0x0, byte]),
},
ImmediateOperand::Word(word) => {
let [low, high] = word.to_le_bytes();
match reg {
crate::register::Register::AX => self.ax.write(word),
crate::register::Register::BX => self.bx.write(word),
crate::register::Register::CX => self.cx.write(word),
crate::register::Register::DX => self.dx.write(word),
// crate::register::Register::AH => {}
// crate::register::Register::AL => {}
// crate::register::Register::BL => {}
// crate::register::Register::BH => {}
// crate::register::Register::CH => {}
// crate::register::Register::CL => {}
// crate::register::Register::DH => {}
// crate::register::Register::DL => {}
crate::register::Register::AH => self.ax.upper = high,
crate::register::Register::AL => self.ax.lower = low,
crate::register::Register::BH => self.ax.upper = high,
crate::register::Register::BL => self.ax.lower = low,
crate::register::Register::CH => self.ax.upper = high,
crate::register::Register::CL => self.ax.lower = low,
crate::register::Register::DH => self.ax.upper = high,
crate::register::Register::DL => self.ax.lower = low,
crate::register::Register::DI => self.di = word,
crate::register::Register::SI => self.si = word,
crate::register::Register::BP => self.bp = word,
crate::register::Register::SP => self.sp = word,
_ => panic!("Tried writing Word to Byte-sized register"),
}
}
}