From 2699292790476eccd726fc5dae179b3a688a1468 Mon Sep 17 00:00:00 2001 From: Johannes Stoelp Date: Fri, 6 Dec 2024 23:32:58 +0100 Subject: asm: add initial support for memory operand only instructions * add dec, inc instruction for with memory operand --- src/lib.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 131440a..6bbfcbf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -88,6 +88,7 @@ pub use reg::{Reg16, Reg32, Reg64, Reg8}; pub use rt::Runtime; /// Type representing a memory operand. +#[derive(Clone, Copy)] pub enum MemOp { /// An indirect memory operand, eg `mov [rax], rcx`. Indirect(Reg64), @@ -123,3 +124,41 @@ impl MemOp { } } } + +/// Trait to give size hints for memory operands. +trait MemOpSized { + fn mem_op(&self) -> MemOp; +} + +macro_rules! impl_memop_sized { + ($(#[$doc:meta] $name:ident)+) => { + $( + #[$doc] + pub struct $name(MemOp); + + impl $name { + /// Create a memory with size hint from a raw memory operand. + pub fn from(op: MemOp) -> Self { + Self(op) + } + } + + impl MemOpSized for $name { + fn mem_op(&self) -> MemOp { + self.0 + } + } + )+ + }; +} + +impl_memop_sized!( + /// A memory operand with a word (8 bit) size hint. + MemOp8 + /// A memory operand with a word (16 bit) size hint. + MemOp16 + /// A memory operand with a dword (32 bit) size hint. + MemOp32 + /// A memory operand with a qword (64 bit) size hint. + MemOp64 +); -- cgit v1.2.3