fix: correctly add displacement for short jumps

This commit is contained in:
2025-05-20 10:12:13 +09:00
parent cb924af0fb
commit fd15e57569
2 changed files with 16 additions and 4 deletions

View File

@@ -634,12 +634,24 @@ impl Disassembler {
0xE8 => Mnemonic::CALL_v(self.parse_word()), 0xE8 => Mnemonic::CALL_v(self.parse_word()),
0xE9 => Mnemonic::JMP_v(self.parse_word()), // add to address of next instruction
0xE9 => {
// first interpret as IByte, then cast for addition
let word = self.parse_word() as IByte as isize;
let next_addr = (self.offset + 1) as isize;
Mnemonic::JMP_v(next_addr + word)
}
0xEA => Mnemonic::JMP_p(Pointer { 0xEA => Mnemonic::JMP_p(Pointer {
segment: self.parse_word(), segment: self.parse_word(),
offset: self.parse_word(), offset: self.parse_word(),
}), }),
0xEB => Mnemonic::JMP_b(self.parse_byte()), // add to address of next instruction
0xEB => {
// first interpret as IByte, then cast for addition
let byte = self.parse_byte() as IByte as isize;
let next_addr = (self.offset + 1) as isize;
Mnemonic::JMP_b(next_addr + byte)
}
0xEC => Mnemonic::IN_ALDX, 0xEC => Mnemonic::IN_ALDX,
0xED => Mnemonic::IN_AXDX, 0xED => Mnemonic::IN_AXDX,

View File

@@ -235,8 +235,8 @@ pub enum Mnemonic {
CALL_Mod(ModRmTarget), CALL_Mod(ModRmTarget),
// JUMP // JUMP
JMP_p(Pointer), JMP_p(Pointer),
JMP_b(Byte), JMP_b(isize), // parses IByte, but stores as isize
JMP_v(Word), JMP_v(isize), // parwses IWord, but stores as isize
JMP_Mod(ModRmTarget), JMP_Mod(ModRmTarget),
// WAIT // WAIT
WAIT, WAIT,