ft: implement disasm in own struct

This makes it easier to implement each opcode,
as the offset calculation and recovery of raw
read bytes is internalized.
This commit is contained in:
2025-05-08 20:18:02 +09:00
parent 1c7d3f3adc
commit df00f59b5a
2 changed files with 76 additions and 79 deletions

View File

@@ -6,7 +6,7 @@ pub type b = u8;
#[allow(non_camel_case_types)]
pub type w = u16;
#[derive(Debug)]
#[derive(Debug, Clone)]
#[allow(dead_code)]
/// A single 'line' of executable ASM is called an Instruction, which
/// contains the `Opcode` that will be executed, alongside its starting offset
@@ -37,7 +37,7 @@ impl fmt::Display for Instruction {
}
}
#[derive(Debug)]
#[derive(Debug, Clone)]
#[allow(dead_code, non_camel_case_types)]
pub enum Opcode {
NOP(),
@@ -61,7 +61,7 @@ impl fmt::Display for Opcode {
}
/// Registers of a 8086 processor
#[derive(Debug)]
#[derive(Debug, Clone)]
#[allow(dead_code)]
pub enum Register {
AX,
@@ -167,11 +167,11 @@ impl fmt::Display for SegmentRegister {
}
/// An immediate byte value for an instruction.
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct ImmediateByte(pub b);
/// An immediate word value for an instruction
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct ImmediateWord(pub w);
macro_rules! impl_display_and_lowerhex {
@@ -195,7 +195,7 @@ impl_display_and_lowerhex!(ImmediateWord);
/// A memory index operand is usually created by ModRM bytes or words.
/// e.g. [bx+si]
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct MemoryIndex {
pub base: Option<Register>,
pub index: Option<Register>,
@@ -226,7 +226,7 @@ impl fmt::Display for MemoryIndex {
}
}
#[derive(Debug)]
#[derive(Debug, Clone)]
#[allow(dead_code)]
/// Displacement for ModRM
pub enum Displacement {