From 559f94ca210e6d5d2835a58e3b67f9802c54e78b Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Wed, 18 Jan 2023 17:42:56 +0100 Subject: [PATCH] Fi write_memory --- src/simulator/machine.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/simulator/machine.rs b/src/simulator/machine.rs index e71328b..0aab638 100644 --- a/src/simulator/machine.rs +++ b/src/simulator/machine.rs @@ -71,10 +71,9 @@ impl Machine { if ![1, 2, 4, 8].contains(&size) { panic!("ERROR write_memory: WRONG `size` PARAMETER ({}), must be 1, 2, 4 or 8", size) } - let map: [u64; 8] = [0xff000000_00000000, 0x00ff0000_00000000, 0x0000ff00_00000000, 0x000000ff_00000000, - 0x00000000_ff00000000, 0x00000000_00ff0000, 0x00000000_0000ff00, 0x00000000_000000ff]; for i in 0..size as usize { - machine.main_memory[address + i as usize] = (value & map[i]) as u8; + let inv_i = size as usize - i - 1; + machine.main_memory[address + i as usize] = ((value & 0xff << (8 * inv_i)) >> (inv_i * 8)) as u8; } } @@ -420,6 +419,7 @@ impl Machine { assert_eq!((43 << 8) + 150, Machine::read_memory(&mut m, 2, 4)); } + #[test] fn test_write_memory() { let mut m = Machine::_init_machine(); Machine::write_memory(&mut m, 2, 6, (43 << 8) + 150);