From 7c080806361e23e2e2a528fb391d6bf9c15404f0 Mon Sep 17 00:00:00 2001 From: Johannes Stoelp Date: Mon, 27 Feb 2023 20:32:32 +0100 Subject: Add MOV tests --- src/lib.rs | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 35f7919..23c9ca0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,7 +24,8 @@ impl MemOp { } /// Encode the `REX` byte. -const fn rex(w: u8, r: u8, x: u8, b: u8) -> u8 { +const fn rex(w: bool, r: u8, x: u8, b: u8) -> u8 { + let w = if w { 1 } else { 0 }; let r = (r >> 3) & 1; let x = (x >> 3) & 1; let b = (b >> 3) & 1; @@ -227,7 +228,7 @@ trait EncodeMR { } fn rex(op1: &MemOp, op2: T) -> Option { - if op1.base().need_rex() || op2.need_rex() { + if op2.need_rex() || (op1.base().is_ext()) { Some(rex(op2.rexw(), op2.idx(), 0, op1.base().idx())) } else { None @@ -235,11 +236,19 @@ trait EncodeMR { } } +impl EncodeMR for Asm {} +impl EncodeMR for Asm { + fn legacy_prefix() -> Option { + Some(0x66) + } +} impl EncodeMR for Asm {} impl EncodeMR for Asm {} // -- Instruction implementations. +// -- MOV : reg reg + impl Mov for Asm { fn mov(&mut self, op1: Reg64, op2: Reg64) { self.encode_rr(0x89, op1, op2); @@ -264,6 +273,8 @@ impl Mov for Asm { } } +// -- MOV : mem reg + impl Mov for Asm { fn mov(&mut self, op1: MemOp, op2: Reg64) { self.encode_mr(0x89, op1, op2); @@ -276,6 +287,20 @@ impl Mov for Asm { } } +impl Mov for Asm { + fn mov(&mut self, op1: MemOp, op2: Reg16) { + self.encode_mr(0x89, op1, op2); + } +} + +impl Mov for Asm { + fn mov(&mut self, op1: MemOp, op2: Reg8) { + self.encode_mr(0x88, op1, op2); + } +} + +// -- MOV : reg mem + impl Mov for Asm { fn mov(&mut self, op1: Reg64, op2: MemOp) { self.encode_rm(0x8b, op1, op2); @@ -288,6 +313,20 @@ impl Mov for Asm { } } +impl Mov for Asm { + fn mov(&mut self, op1: Reg16, op2: MemOp) { + self.encode_rm(0x8b, op1, op2); + } +} + +impl Mov for Asm { + fn mov(&mut self, op1: Reg8, op2: MemOp) { + self.encode_rm(0x8a, op1, op2); + } +} + +// -- MOV : reg imm + impl Mov for Asm { fn mov(&mut self, op1: Reg64, op2: Imm64) { self.encode_oi(0xb8, op1, op2); -- cgit v1.2.3