Новая инструкция: rjmp #1

Merged
n3tael merged 2 commits from rjmp into master 2024-02-08 18:45:11 +00:00
Showing only changes of commit de2d98bfec - Show all commits

View File

@ -1,8 +1,9 @@
use crate::stack::StackVec;
use crate::{errors::RunError, 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;
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;
}