new instruction rjmp
This commit is contained in:
		
							parent
							
								
									d6e290f916
								
							
						
					
					
						commit
						b3d1380eba
					
				@ -89,6 +89,7 @@ pub fn execute(stack: &mut Stack, mut origin_stack: Option<&mut Stack>, mod_name
 | 
			
		||||
 | 
			
		||||
            // Labels
 | 
			
		||||
            "jmp"  => instructions::jmp::jmp(&mut stack.labels, &mut stack.program_counter, instruction.data),
 | 
			
		||||
            "rjmp" => instructions::rjmp::rjmp(&mut stack.memory, &mut stack.labels, &mut stack.program_counter),
 | 
			
		||||
            "jnz"  => instructions::jnz::jnz(&mut stack.memory, &mut stack.labels, &mut stack.program_counter, instruction.data),
 | 
			
		||||
            "jz"   => instructions::jz::jz(&mut stack.memory, &mut stack.labels, &mut stack.program_counter, instruction.data),
 | 
			
		||||
            "kjnz" => instructions::kjnz::kjnz(&mut stack.memory, &mut stack.labels, &mut stack.program_counter, instruction.data),
 | 
			
		||||
 | 
			
		||||
@ -39,3 +39,4 @@ pub mod print;
 | 
			
		||||
pub mod println;
 | 
			
		||||
pub mod insert;
 | 
			
		||||
pub mod random;
 | 
			
		||||
pub mod rjmp;
 | 
			
		||||
							
								
								
									
										8
									
								
								src/instructions/rjmp.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								src/instructions/rjmp.rs
									
									
									
									
									
										Normal 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;
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user