0000000001_Assembler and Virtual Machine (EN) - MohammadMovi/VDOS GitHub Wiki


🎯 Goal

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 Set

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)


πŸ“‚ Project Files

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

🧠 Memory and Registers

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
}


πŸš€ How to Run

# Step 1 – Assemble
python assembler.py

Step 2 – Run bytecode

python vm.py


πŸ§ͺ Sample Output

πŸš€ 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


πŸ“š Key Concepts Learned

  • 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


πŸ“… Timeline

Event Persian Date Gregorian Date
Step Started 1403/03/17 2025-06-06
Step Finished 1403/03/17 2025-06-06

▢️ What’s Next?

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


---
⚠️ **GitHub.com Fallback** ⚠️