fix: correctly parse word instead of byte for GPR

This commit is contained in:
2025-05-13 12:35:38 +09:00
parent 47a002cd79
commit 27b39ee94a
2 changed files with 7 additions and 3 deletions

View File

@@ -204,6 +204,8 @@ impl Disassembler {
}
/// Match the modrm reg bits to the GPR1 mnemonics.
/// GPR always has an imm value as second operand, but is available in both
/// Byte and Word length.
pub fn modrm_reg_to_mnemonic(reg: u8, target: ModRmTarget, imm: OperandWidth) -> Mnemonic {
match imm {
OperandWidth::Byte(b) => match reg {

View File

@@ -26,7 +26,8 @@ macro_rules! modrms {
}
#[macro_export]
/// Generate a GPR instruction from modrm byte for byte
/// Generate a GPR instruction from modrm byte for byte.
/// GPR always has an imm value as second operand.
macro_rules! modrmgprb {
($self:ident) => {{
let (target, reg) = $self.parse_modrm_byte(OperandWidth::Byte(0));
@@ -37,10 +38,11 @@ macro_rules! modrmgprb {
#[macro_export]
/// Generate a GPR instruction from modrm byte for word
/// GPR always has an imm value as second operand.
macro_rules! modrmgprv {
($self:ident) => {{
let (target, reg) = $self.parse_modrm_byte(OperandWidth::Word(0));
let imm = $self.parse_byte();
Self::modrm_reg_to_mnemonic(reg, target, OperandWidth::Word(imm.into()))
let imm = $self.parse_word();
Self::modrm_reg_to_mnemonic(reg, target, OperandWidth::Word(imm))
}};
}