diff --git a/src/instructions/rjmp.rs b/src/instructions/rjmp.rs index 71b5f90..c3922d2 100644 --- a/src/instructions/rjmp.rs +++ b/src/instructions/rjmp.rs @@ -1,8 +1,9 @@ -use crate::stack::StackVec; +use crate::{errors::RunError, stack::StackVec}; pub fn rjmp(memory: &mut StackVec, labels: &mut [Option; 256], program_counter: &mut u16) { let start = memory.pop() as usize; let end = memory.pop() as usize; + let rand = fastrand::usize(start..end + 1); - *program_counter = (labels[fastrand::usize(start..end)].unwrap() - 1) as u16; + *program_counter = (labels[rand].expect(&format!("{}", RunError::UnknownLabel(rand as u16))) - 1) as u16; } \ No newline at end of file