Skip to content

Commit

Permalink
fix set and setne
Browse files Browse the repository at this point in the history
  • Loading branch information
lenawanel committed Apr 20, 2024
1 parent 08e8cd3 commit 234ed8c
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 45 deletions.
33 changes: 9 additions & 24 deletions src/emu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ impl Emu {
} else {
self.unset_flag(Flag::ZF);
}
if (and_res & 0xff).count_ones() & 1 > 0 {
if (and_res & 0xff).count_ones() & 1 == 0 {
self.set_flag(Flag::PF);
} else {
self.unset_flag(Flag::PF);
Expand Down Expand Up @@ -1102,11 +1102,14 @@ impl Emu {
// movsxd, as documented by https://www.felixcloutier.com/x86/movsx:movsxd
// let's hope that this sign extends
match bitness(instruction) {
Bitness::Eight => sized_mov!(i8),
Bitness::Eight => unsafe { unreachable_unchecked() },
Bitness::Sixteen => sized_mov!(i16),
Bitness::ThirtyTwo => sized_mov!(i32),
Bitness::SixtyFour => sized_mov!(i64),
Bitness::HundredTwentyEigth => sized_mov!(i128),
Bitness::SixtyFour => {
let val: i32 = self.get_val(instruction, 1)?;
self.set_val(instruction, 0, val as i64)?;
}
Bitness::HundredTwentyEigth => unsafe { unreachable_unchecked() },
}
}
Mnemonic::Movzx => {
Expand Down Expand Up @@ -1218,28 +1221,10 @@ impl Emu {
}
}
Mnemonic::Sete => {
macro_rules! sized_sete {
($typ:ty,$size:literal) => {{
if self.get_flag(Flag::ZF) {
self.set_val::<$typ, $size>(instruction, 0, 1)?;
} else {
self.set_val::<$typ, $size>(instruction, 0, 0)?;
}
}};
}
match_bitness_ts!(sized_sete)
self.set_val(instruction, 0, self.get_flag(Flag::ZF) as u8)?;
}
Mnemonic::Setne => {
macro_rules! sized_sete {
($typ:ty,$size:literal) => {{
if !self.get_flag(Flag::ZF) {
self.set_val::<$typ, $size>(instruction, 0, 1)?;
} else {
self.set_val::<$typ, $size>(instruction, 0, 0)?;
}
}};
}
match_bitness_ts!(sized_sete)
self.set_val(instruction, 0, !self.get_flag(Flag::ZF) as u8)?;
}
/*
+----------------------+
Expand Down
Binary file removed test_flags
Binary file not shown.
15 changes: 0 additions & 15 deletions test_flags.asm

This file was deleted.

Binary file removed testflags
Binary file not shown.
6 changes: 0 additions & 6 deletions testflags.asm

This file was deleted.

0 comments on commit 234ed8c

Please sign in to comment.