From d44466c852dd353166c79d1cc618646b21e17f8c Mon Sep 17 00:00:00 2001 From: Johannes Stoelp Date: Mon, 27 Feb 2023 23:35:32 +0100 Subject: Add JNZ and Reg32 ADD, DEC, TEST for readme example --- src/insn.rs | 6 ++++++ src/insn/add.rs | 6 ++++++ src/insn/dec.rs | 6 ++++++ src/insn/jnz.rs | 7 +++++++ src/insn/test.rs | 6 ++++++ src/prelude.rs | 2 +- 6 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/insn/jnz.rs diff --git a/src/insn.rs b/src/insn.rs index 8351c54..f3ba18d 100644 --- a/src/insn.rs +++ b/src/insn.rs @@ -1,6 +1,7 @@ mod add; mod dec; mod jmp; +mod jnz; mod jz; mod mov; mod ret; @@ -21,6 +22,11 @@ pub trait Jmp { fn jmp(&mut self, op1: T); } +pub trait Jnz { + /// Emit a conditional jump if not zero instruction (`ZF = 0`). + fn jnz(&mut self, op1: T); +} + pub trait Jz { /// Emit a conditional jump if zero instruction (`ZF = 1`). fn jz(&mut self, op1: T); diff --git a/src/insn/add.rs b/src/insn/add.rs index b8456c4..3757d14 100644 --- a/src/insn/add.rs +++ b/src/insn/add.rs @@ -5,3 +5,9 @@ impl Add for Asm { self.encode_rr(0x01, op1, op2); } } + +impl Add for Asm { + fn add(&mut self, op1: Reg32, op2: Reg32) { + self.encode_rr(0x01, op1, op2); + } +} diff --git a/src/insn/dec.rs b/src/insn/dec.rs index 7de5a54..c5803e7 100644 --- a/src/insn/dec.rs +++ b/src/insn/dec.rs @@ -5,3 +5,9 @@ impl Dec for Asm { self.encode_r(0xff, 1, op1); } } + +impl Dec for Asm { + fn dec(&mut self, op1: Reg32) { + self.encode_r(0xff, 1, op1); + } +} diff --git a/src/insn/jnz.rs b/src/insn/jnz.rs new file mode 100644 index 0000000..6517bd7 --- /dev/null +++ b/src/insn/jnz.rs @@ -0,0 +1,7 @@ +use crate::prelude::*; + +impl Jnz<&mut Label> for Asm { + fn jnz(&mut self, op1: &mut Label) { + self.encode_jmp_label(&[0x0f, 0x85], op1); + } +} diff --git a/src/insn/test.rs b/src/insn/test.rs index 1319e3f..25f1680 100644 --- a/src/insn/test.rs +++ b/src/insn/test.rs @@ -5,3 +5,9 @@ impl Test for Asm { self.encode_rr(0x85, op1, op2); } } + +impl Test for Asm { + fn test(&mut self, op1: Reg32, op2: Reg32) { + self.encode_rr(0x85, op1, op2); + } +} diff --git a/src/prelude.rs b/src/prelude.rs index 29e7265..e1334ea 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -5,4 +5,4 @@ pub use crate::imm::{Imm16, Imm32, Imm64, Imm8}; pub use crate::label::Label; pub use crate::reg::{Reg16, Reg32, Reg64, Reg8}; -pub use crate::insn::{Add, Dec, Jmp, Jz, Mov, Test}; +pub use crate::insn::{Add, Dec, Jmp, Jnz, Jz, Mov, Test}; -- cgit v1.2.3