Fi write_memory
This commit is contained in:
parent
66eeb8f2b7
commit
559f94ca21
@ -71,10 +71,9 @@ impl Machine {
|
|||||||
if ![1, 2, 4, 8].contains(&size) {
|
if ![1, 2, 4, 8].contains(&size) {
|
||||||
panic!("ERROR write_memory: WRONG `size` PARAMETER ({}), must be 1, 2, 4 or 8", 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 {
|
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));
|
assert_eq!((43 << 8) + 150, Machine::read_memory(&mut m, 2, 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
fn test_write_memory() {
|
fn test_write_memory() {
|
||||||
let mut m = Machine::_init_machine();
|
let mut m = Machine::_init_machine();
|
||||||
Machine::write_memory(&mut m, 2, 6, (43 << 8) + 150);
|
Machine::write_memory(&mut m, 2, 6, (43 << 8) + 150);
|
||||||
|
Loading…
Reference in New Issue
Block a user