procem
procem is a toy Rust library that provides a flexible processor emulator, loosely inspired by the ARM architecture. It allows you to define and execute custom instruction sets, manage registers, flags, and stack memory, and run assembly-like programs.
Features
Processor: Emulates a processor with general-purpose registers, program counter, stack pointer, flags, and a stack.Program: Container for a sequence of instructions to be executed by the processor.Instruction: Trait for defining custom instruction sets. A default instruction set is implemented in the procem_default crate.Registers: General-purpose registers, program counter, stack pointer, and flags.Stack: Fixed-size stack for processor operations.Word: Trait for word-size types. Word is already implemented for all signed integer types.
Customization
You can implement your own instruction set by implementing the Instruction trait, and support custom word types by implementing the Word trait. Alternatively, you can use the default instruction set and word types.
Example: Using procem_default
use ;
use assemble;
// Assemble a program from asm
let program = .unwrap;
// Create a processor and run the program
const STACK_SIZE: usize = 1024;
let mut processor = builder
.with_program
.build;
let _ = processor.run_program;
// Inspect register values
assert_eq!;
Example: Custom Instruction Set
use ;
// Define your own word type
;
// Define your own instruction set
// Create a program and processor using your custom types
let program = new;
let mut processor = builder
.with_program
.build;