use crate::emu64;
#[test]
fn add_updates_register() {
let mut emu = emu64();
let code = [
0x48, 0xc7, 0xc0, 0x05, 0x00, 0x00, 0x00, 0x48, 0xc7, 0xc3, 0x07, 0x00, 0x00, 0x00, 0x48, 0x01, 0xd8, ];
emu.load_code_bytes(&code);
for _ in 0..3 {
emu.step();
}
assert_eq!(emu.regs().rax, 12);
}
#[test]
fn xor_self_sets_zero_flag() {
let mut emu = emu64();
let code = [
0x48, 0xc7, 0xc0, 0x99, 0x00, 0x00, 0x00, 0x31, 0xc0, ];
emu.load_code_bytes(&code);
emu.step();
emu.step();
assert_eq!(emu.regs().rax, 0);
assert!(emu.flags().f_zf, "xor eax,eax must set ZF");
}
#[test]
fn garbage_code_does_not_panic() {
let mut emu = emu64();
let junk = [0xff, 0xff, 0xff, 0xff, 0x00, 0xcc, 0xf1, 0x0f, 0x0b];
emu.load_code_bytes(&junk);
for _ in 0..8 {
if !emu.step() {
break;
}
}
}
#[test]
fn divide_by_zero_does_not_panic() {
let mut emu = emu64();
let code = [
0x48, 0x31, 0xd2, 0x48, 0xc7, 0xc0, 0x0a, 0x00, 0x00, 0x00, 0x48, 0xc7, 0xc3, 0x00, 0x00, 0x00, 0x00, 0x48, 0xf7, 0xf3, ];
emu.load_code_bytes(&code);
for _ in 0..4 {
if !emu.step() {
break;
}
}
}