Basic Rust app that will simulate some of the flows on computer, including:
-
RAM (
256 bytes
) - can be read, written and dumped for inspection.Addressed via hexadecimal addressed.
Each memory cell is 8 bits (1 byte) wide
-
CPU - Supports basic arithmetic and logic operations (
ADD, AND, OR, NAND, NOR, XOR, NOT
).ATM asm-like code directly executed by the CPU, I'm not sure how it supposed to be.
CPU supports
8 general-purpose 8-bit
registers to hold data during execution. -
More on the way, but it's still area for a research.
Simulation has option to write simple assembly-like programs with small set of instructions:
VER
- Toggle verbosity to enable/disable detailed execution logs.MOV QMOV
- Assingning RAM/Another Register's/Immediate Value to the registerINIT
- Initialize memory addresses with values.LOAD
- Load a value from memory into a register.ADD SUB MUL DIV
- basic arythemitcsSTORE
- Store a value from a register into memory.OUT
- Output register or memory/values.CLEAR
- Clear the register or memoryHALT
- Stop the execution.IF/ELSE
- If and else statement that supports basic operations between registers, memory and values.
While I'm aiming to make it as low-level and realistic as possible - some of the features jsut could't be realisied due to number of reasons, one of them - I'm still researching about flows and how everything is working.
BIOS> filename.asm
You can play around with some example programs:
calculator.asm
- Addition calculator programgates.asm
- Test of the Logic Gatesif_test.asm
- Simple IF ELSE logicprogram.asm
- Simple collection of different instructionsmov_test.asm
- Test of MOV instructiondiv.asm
- Division Programincdec.asm
- Increment and Decrement Registermul.asm
- Multiplication Programqmov.asm
- QMOV Testsub.asm
- Substract Instruction
; Example program
VER = 1 ; Enable debug (VERBOSE) prints of execution
INIT [0x08] = 0b00000101 ; Initialize memory at address 0x08 with binary 5
INIT [0x10] = 0b00001010 ; Initialize memory at address 0x10 with binary 10
INIT [0x1F] = 0b00001010
LOAD R1, [0x08] ; Load value from address 0x08 into register R1
LOAD R2, [0x10] ; Load value from address 0x10 into register R2
ADD R1, R2, R3 ; Add R1 and R2, store result in R3
STORE R3, [0x20] ; Store the result in memory address 0x20
OUT R3 ; Display the register R3
CLEAR [0x20] ; Clear the value in memory address 0x20
CLEAR [0x08] ; Clear the value in memory address 0x08
CLEAR [0x10] ; Clear the value in memory address 0x10
CLEAR [0x1F] ; Clear the value in memory address 0x1F
VER = 0 ; Disable debug (VERBOSE) prints of execution
HALT ; Stop execution
- Make sure you have rust installed
- Clone the repo:
git clone https://github.com/denver-code/pc_simulation_rs cd pc_simulation_rs
- Run or Build the project:
# Build cargo build --release (Optional) # Run cargo run
Once the simulator is powered on, you can use the following commands in the BIOS prompt:
- address [hex]: View the value stored in memory at the given address (in hexadecimal in square brackets).
- memory_dump: Display the entire contents of the RAM.
- exit: Quit the BIOS.
- [filename].asm: Load and run an assembly-like program from a file.