This commit is contained in:
2026-06-13 13:44:03 -04:00
parent bdeb0d821c
commit 1e39675c29
8 changed files with 94 additions and 46 deletions
+29 -3
View File
@@ -172,9 +172,35 @@ impl Code {
self.bytes.push(0xc3);
}
pub fn sub(&mut self) {
// sub esp 40 iirc
self.bytes.extend([0x48, 0x83, 0xec, 0x28]);
pub fn sub(&mut self, mut dst: Reg, src: impl Into<Imm>) -> ERes {
let mut src = src.into();
let mut width = src.width_signed()?;
let dst_width = dst.width().min(Width::B32);
self.prefix16(dst_width);
self.rex(dst, 0, 0, dst);
if width > dst_width {
width = src.width_unsigned()?;
if dst.width() == Width::B64 || width > dst_width {
return Err("immediate overflow".into());
}
src = src.reinterpret(dst_width);
width = src.width_signed()?;
}
if dst.width() == Width::B8 {
self.bytes.push(0x80);
} else {
if width == Width::B8 {
self.bytes.push(0x83);
} else {
self.bytes.push(0x81);
width = dst_width;
}
}
self.bytes.push(modrm(0b11, 0b101, dst.base()));
self.imm(src, width);
Ok(())
}
fn prefix16(&mut self, width: impl Into<Width>) {