Add tests momery
This commit is contained in:
parent
b75c7b2d96
commit
66eeb8f2b7
@ -308,9 +308,9 @@ impl Machine {
|
|||||||
},
|
},
|
||||||
RISCV_OP_SLT => {
|
RISCV_OP_SLT => {
|
||||||
if machine.int_reg[inst.rs1 as usize] < machine.int_reg[inst.rs2 as usize] {
|
if machine.int_reg[inst.rs1 as usize] < machine.int_reg[inst.rs2 as usize] {
|
||||||
machine.int_reg[inst.rd as usize] = 1;
|
machine.int_reg[inst.rd as usize] = 1;
|
||||||
} else {
|
} else {
|
||||||
machine.int_reg[inst.rd as usize] = 0;
|
machine.int_reg[inst.rd as usize] = 0;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
RISCV_OP_SLTU => {
|
RISCV_OP_SLTU => {
|
||||||
@ -410,5 +410,20 @@ impl Machine {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
|
use crate::simulator::machine::Machine;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_read_memory() {
|
||||||
|
let mut m = Machine::_init_machine();
|
||||||
|
m.main_memory[4] = 43;
|
||||||
|
m.main_memory[5] = 150;
|
||||||
|
assert_eq!((43 << 8) + 150, Machine::read_memory(&mut m, 2, 4));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_write_memory() {
|
||||||
|
let mut m = Machine::_init_machine();
|
||||||
|
Machine::write_memory(&mut m, 2, 6, (43 << 8) + 150);
|
||||||
|
assert_eq!(43, m.main_memory[6]);
|
||||||
|
assert_eq!(150, m.main_memory[7]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user