0000000001_Assembler and Virtual Machine (EN) - MohammadMovi/VDOS GitHub Wiki
In this step, we simulate the earliest form of CPU logic from the 1950s by:
- Defining a custom Assembly language
- Writing an assembler in Python to convert
.asm
files to.vdos
bytecode - Building a simple virtual CPU to execute the bytecode
Instruction | Description | Opcode |
---|---|---|
LOAD N |
Load value N into ACC |
01 NN |
ADD N |
Add N to ACC |
02 NN |
STORE X |
Store ACC into memory X
|
03 XX |
HALT |
Stop program execution | FF 00 |
> ACC is the main CPU register (Accumulator)
File | Purpose |
---|---|
example.asm |
Sample code in VDOS Assembly |
assembler.py |
Converts .asm to .vdos
|
program.vdos |
Output bytecode file |
vm.py |
Virtual machine to run bytecode |
Register:
- ACC (Accumulator)
Memory:
- A = 0
- B = 0
- C = 0
</code></pre>
<p>Defined in <code inline="">vm.py</code> as:</p>
<pre><code class="language-python">memory = {
"A": 0,
"B": 0,
"C": 0
}
# Step 1 β Assemble
python assembler.py
Step 2 β Run bytecode
python vm.py
π Running VDOS Bytecode:
πΉ LOAD 5
β ADD β ACC = 8
πΎ STORE ACC (8) β A
πΉ LOAD 2
β ADD β ACC = 6
πΎ STORE ACC (6) β B
β HALT
π¦ Final Memory State:
π§ A = 8
π§ B = 6
π§ C = 0
-
How early CPUs executed simple instruction sets
-
Binary translation from human-readable commands to bytecode
-
Simulated memory and register operations
-
Foundation for real bootloaders and kernels
Event | Persian Date | Gregorian Date |
---|---|---|
Step Started | 1403/03/17 | 2025-06-06 |
Step Finished | 1403/03/17 | 2025-06-06 |
Step 02 β Bootloader with NASM and QEMU
Writing a real 512-byte boot sector
BIOS-level execution on QEMU
Print βHello from VDOSβ from real-mode assembly
---