Your First Program
Let's write a simple program that adds two numbers and prints the result.
Navigate to the Romasm IDE in your browser.
Enter this simple program:
; Add two numbers
LOAD R0, 10 ; Load 10 into R0
LOAD R1, 20 ; Load 20 into R1
ADD R0, R1 ; R0 = R0 + R1 (now 30)
PRINT R0 ; Print the result
Click the "Run" button. You should see 30 in the output.
Understanding the Code
LOAD Instruction
LOAD R0, 10 loads the value 10 into register R0.
Registers are named R0 through R8, which map to Roman numerals I through IX.
ADD Instruction
ADD R0, R1 adds the value in R1 to R0 and stores the result in R0.
After this instruction, R0 contains 30 (10 + 20).
PRINT Instruction
PRINT R0 outputs the value in R0 to the console.
More Examples
Example 1: Multiplication
; Calculate 5 * 7
LOAD R0, 5
LOAD R1, 7
MUL R0, R1 ; R0 = R0 * R1 = 35
PRINT R0
Example 2: Loop
; Print numbers 1 to 5
LOAD R0, 1 ; Counter
LOAD R1, 5 ; Max value
loop:
PRINT R0 ; Print current number
INC R0 ; Increment counter
CMP R0, R1 ; Compare R0 with R1
JLE loop ; Jump to loop if R0 <= R1
Example 3: Conditional
; Check if number is even
LOAD R0, 8
LOAD R1, 2
MOD R0, R1 ; R0 = R0 % 2
LOAD R2, 0
CMP R0, R2 ; Compare remainder with 0
JEQ is_even ; Jump if equal (even)
; Odd number
LOAD R3, 1
PRINT R3
JMP done
is_even:
LOAD R3, 0
PRINT R3
done:
Using Standard Library Functions
Romasm includes a standard library with pre-built functions. To use them, you need to link your code with the stdlib.
Example: Calculate Sine
; Calculate sin(30 degrees)
; Note: This requires linking with stdlib
LOAD R0, 3000 ; 30 degrees (scaled by 100)
CALL sin ; Call sin function from stdlib
; Result in R0 (scaled by 1000)
PRINT R0
Note: In the IDE, you'll need to enable stdlib linking. In the calculator, this is handled automatically.
🏛️ Build a Real OS with RomanOS!
RomanOS - Bootable Operating System
Want to build a real operating system? Romasm can compile to actual x86 machine code!
RomanOS lets you write a complete bootable OS in Romasm that runs on real hardware. Check out the RomanOS documentation to learn more.
Features:
- ✅ Compiles to real x86 assembly
- ✅ Creates bootable images
- ✅ Runs on QEMU and real hardware
- ✅ Advanced code optimizations (90-98% of hand-optimized ASM)
- ✅ Complete BIOS library
Next Steps
- Learn all instructions - Complete reference
- Syntax & conventions - Writing clean Romasm code
- Standard library - Available functions
- Try the IDE - Experiment with code
- Try the Calculator - Plot functions and draw graphics
- Build an OS! - RomanOS for real hardware