new instruction rjmp

This commit is contained in:
2024-02-08 20:04:02 +02:00
parent d6e290f916
commit b3d1380eba
3 changed files with 11 additions and 1 deletions
+2 -1
View File
@@ -38,4 +38,5 @@ pub mod kjz;
pub mod print;
pub mod println;
pub mod insert;
pub mod random;
pub mod random;
pub mod rjmp;
+8
View File
@@ -0,0 +1,8 @@
use crate::stack::StackVec;
pub fn rjmp(memory: &mut StackVec, labels: &mut [Option<i16>; 256], program_counter: &mut u16) {
let start = memory.pop() as usize;
let end = memory.pop() as usize;
*program_counter = (labels[fastrand::usize(start..end)].unwrap() - 1) as u16;
}