From de2d98bfec164e12c2711c8c394057d5678ae7ea Mon Sep 17 00:00:00 2001 From: n3tael Date: Thu, 8 Feb 2024 20:29:37 +0200 Subject: [PATCH] fix --- src/instructions/rjmp.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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