add
This commit is contained in:
@@ -172,7 +172,7 @@ impl Code {
|
||||
self.bytes.push(0xc3);
|
||||
}
|
||||
|
||||
pub fn sub(&mut self, dst: Reg, src: impl Into<Imm>) -> ERes {
|
||||
fn add_sub(&mut self, dst: Reg, src: impl Into<Imm>, ext: u8) -> ERes {
|
||||
let mut src = src.into();
|
||||
let mut width = src.width_signed()?;
|
||||
let dst_width = dst.width().min(Width::B32);
|
||||
@@ -198,11 +198,19 @@ impl Code {
|
||||
width = dst_width;
|
||||
}
|
||||
|
||||
self.bytes.push(modrm(0b11, 0b101, dst.base()));
|
||||
self.bytes.push(modrm(0b11, ext, dst.base()));
|
||||
self.imm(src, width);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn add(&mut self, dst: Reg, src: impl Into<Imm>) -> ERes {
|
||||
self.add_sub(dst, src, 0)
|
||||
}
|
||||
|
||||
pub fn sub(&mut self, dst: Reg, src: impl Into<Imm>) -> ERes {
|
||||
self.add_sub(dst, src, 5)
|
||||
}
|
||||
|
||||
fn prefix16(&mut self, width: impl Into<Width>) {
|
||||
if width.into() == Width::B16 {
|
||||
self.bytes.push(0x66);
|
||||
|
||||
@@ -37,9 +37,15 @@ fn mov() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sub() {
|
||||
fn add_sub() {
|
||||
let c = &mut TestCtx::new("mov");
|
||||
|
||||
for dst in regs() {
|
||||
for src in imms() {
|
||||
eq(c, format!("add {dst}, {src}"), |c| c.add(dst, src))
|
||||
}
|
||||
}
|
||||
|
||||
for dst in regs() {
|
||||
for src in imms() {
|
||||
eq(c, format!("sub {dst}, {src}"), |c| c.sub(dst, src))
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user