ft(interpreter): impl short jumps
This commit is contained in:
@@ -184,32 +184,34 @@ impl Disassembler {
|
||||
/// offset.
|
||||
/// Returns the read byte added to the address of the subsequent instruction
|
||||
/// to act as a relative offset (Intel Jb operand).
|
||||
fn parse_j_byte(&mut self) -> Result<isize, DisasmError> {
|
||||
/// The returned `usize` will be the subsequent instruction to jump to.
|
||||
fn parse_j_byte(&mut self) -> Result<usize, DisasmError> {
|
||||
log::debug!("Attempting to parse Jb at {:#04x} ...", self.offset);
|
||||
// first interpret as 2-complement, then cast for addition
|
||||
let byte = self.parse_byte()? as IByte as isize;
|
||||
let next_addr = (self.offset + 1) as isize;
|
||||
log::debug!(
|
||||
"Parsed Jb consists of {byte:#04x} + {next_addr:#04x} = {:#04x}",
|
||||
byte + next_addr
|
||||
(byte + next_addr) as usize
|
||||
);
|
||||
Ok(byte + next_addr)
|
||||
Ok((byte + next_addr) as usize)
|
||||
}
|
||||
|
||||
/// Parse a word of the binary, interpret it as signed and advance the
|
||||
/// offset.
|
||||
/// Returns the read word added to the address of the subsequent instruction
|
||||
/// to act as a relative offset (Intel Jw/Jv operand).
|
||||
pub fn parse_j_word(&mut self) -> Result<isize, DisasmError> {
|
||||
/// The returned `usize` will be the subsequent instruction to jump to.
|
||||
pub fn parse_j_word(&mut self) -> Result<usize, DisasmError> {
|
||||
log::debug!("Attempting to parse Jv at {:#04x} ...", self.offset);
|
||||
// first interpret as 2-complement, then cast for addition
|
||||
let word = self.parse_word()? as IWord as isize;
|
||||
let next_addr = (self.offset + 1) as isize;
|
||||
log::debug!(
|
||||
"Parsed Jv consists of {word:#04x} + {next_addr:#04x} = {:#04x}",
|
||||
word + next_addr
|
||||
(word + next_addr) as usize
|
||||
);
|
||||
Ok(word + next_addr)
|
||||
Ok((word + next_addr) as usize)
|
||||
}
|
||||
|
||||
/// Parse a single pointer of the binary and advance the offset.
|
||||
|
||||
Reference in New Issue
Block a user