4-bit virtual CPU
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

41 lines
833 B

// SPDX-License-Identifier: MIT
// Copyright Murad Karammaev, Nikita Kuzmin
mod assembler;
mod cpu;
mod instruction;
use assembler::Assembler;
use cpu::*;
fn main() {
/*
0b01001111, // R0 = 0xF
0b01010011, // R1.l = 0x3
0b11100100, // ADD
0b00100000, // [0] = R0
0b11111000, // R0 = 0
0b11110101, // HALT
*/
let asm = Assembler::new();
let code = asm
.assemble(
r#"
MOV R0.h, 0x0
MOV R0.l, 0xF
MOV R1.l, 0x3
ADD
MOV [0], R0
ZERO R0
HALT
"#,
)
.unwrap();
let mut cpu = Cpu::new(&code);
loop {
if cpu.step() {
break;
}
}
cpu.visualize();
}