Romasm Language Overview

Understanding the Romasm assembly language and virtual machine

What is Romasm?

Romasm is a custom assembly language that uses Roman numerals for registers and instruction opcodes. It's designed to be:

  • Educational: Learn assembly language concepts with a unique twist
  • Functional: Full-featured instruction set with arithmetic, control flow, and I/O
  • Web-based: Runs entirely in the browser using a JavaScript virtual machine
  • Mathematical: Includes standard library for advanced math (trig, calculus, etc.)

Architecture Overview

Romasm Assembly Code
(Text)
Assembler
(romasm-assembler.js)
Instruction Objects
(JSON)
Virtual Machine
(romasm-vm.js)
Execution Results

Romasm code is assembled into instruction objects, then executed by a JavaScript-based virtual machine

Key Features

🏛️ Roman Numeral Registers

Registers use Roman numerals: R0 = I, R1 = II, R2 = III, etc.

LOAD R0, 10    ; R0 (register I) = 10
LOAD R1, 20    ; R1 (register II) = 20
ADD R0, R1     ; R0 = R0 + R1 = 30

📚 Standard Library

Pre-built functions for common operations:

  • Math: factorial, power, square root
  • Trigonometry: sin, cos, tan (Taylor series)
  • Calculus: derivatives, integrals (numerical methods)
  • Advanced: exponential, logarithm
LOAD R0, 3000        ; 30 degrees (scaled by 100)
CALL sin              ; Call stdlib sin function
; Result in R0

🎨 Canvas Drawing

Direct canvas manipulation from Romasm code:

CLEAR
MOVE R0, R1          ; Move to (x, y)
DRAW R2, R3          ; Draw line to (x, y)
STROKE               ; Render the path

🔗 Linking System

Automatically links user code with standard library functions. Write CALL sin and the linker resolves it to the stdlib function address.

🔢 Big Integer Support

Handle numbers beyond JavaScript's safe integer limit (2^53) using arbitrary-precision arithmetic.

Virtual Machine vs. Native Execution

🌐 Browser VM (Default)

The Romasm Virtual Machine is a JavaScript-based interpreter that executes Romasm instructions in the browser. It's:

  • ✅ A JavaScript interpreter (like Python's interpreter or the JVM)
  • ✅ Executes instructions sequentially in a loop
  • ✅ Maintains registers, memory, stack, and program counter
  • ✅ All math operations are performed by executing Romasm instructions

When you write ADD R0, R1, the VM executes:

this.registers['I'] += this.registers['II'];

Perfect for learning, prototyping, and web-based tools!

⚡ Native Hardware (RomanOS)

But wait - Romasm can also compile to real x86 machine code!

With RomanOS, your Romasm code:

  • ✅ Compiles to real x86 assembly
  • ✅ Assembles to machine code with NASM
  • ✅ Runs on actual hardware (QEMU or real machines)
  • ✅ Highly optimized (90-98% of hand-optimized assembly speed)

This means you can write a complete operating system in Romasm that boots on real hardware!

Learn more about RomanOS →

Fixed-Point Arithmetic

Romasm uses fixed-point arithmetic for decimal numbers. Numbers are scaled by a factor (typically 100 or 1000) to represent decimals as integers.

Example: Sine Function

To represent 30.5 degrees:

  • Scale by 100: 3050 (represents 30.50)
  • Scale by 1000: 30500 (represents 30.500)

When calling sin(30), you pass 3000 (30 × 100), and the function returns a scaled result (e.g., 500 for sin(30°) ≈ 0.5, scaled by 1000).

Next Steps