Basic Syntax
Instructions
Each line contains one instruction:
INSTRUCTION operand1, operand2
Example:
LOAD R0, 10
ADD R0, R1
PRINT R0
Comments
Comments start with ; and continue to the end of the line:
; This is a comment
LOAD R0, 10 ; Load 10 into R0 (inline comment)
Labels
Labels mark locations in code and end with ::
my_label:
LOAD R0, 10
JMP my_label ; Jump to my_label
Labels are used for:
- Jump targets (
JMP label) - Function entry points (
CALL function_name) - Loop start/end points
Case Sensitivity
Romasm is case-insensitive for instructions and registers:
LOAD R0, 10 ; Valid
load r0, 10 ; Also valid
Load R0, 10 ; Also valid
However, labels are case-sensitive, so be consistent!
Operand Types
Registers
Registers are specified as R0 through R8:
LOAD R0, 10 ; R0 is a register
ADD R0, R1 ; Both R0 and R1 are registers
Immediate Values
Literal numbers can be used directly:
LOAD R0, 42 ; 42 is an immediate value
CMP R0, 10 ; 10 is an immediate value
Memory Addresses
Memory is accessed using square brackets:
LOAD R0, [100] ; Load from memory address 100
STORE R0, [200] ; Store to memory address 200
Labels as Operands
Labels can be used as jump targets:
JMP my_label ; Jump to label
CALL my_function ; Call function at label
Common Patterns
Loading Constants
; Load common constants into registers
LOAD R1, 1 ; Constant 1
LOAD R2, 2 ; Constant 2
LOAD R3, 100 ; Scaling factor
LOAD R4, 1000 ; Another scaling factor
Loops
; Count from 1 to 10
LOAD R0, 1 ; Counter
LOAD R1, 10 ; Max value
loop:
PRINT R0
INC R0
CMP R0, R1
JLE loop ; Jump if R0 <= R1
Conditionals
; If-else pattern
LOAD R0, 10
LOAD R1, 5
CMP R0, R1
JGT greater ; Jump if R0 > R1
; R0 <= R1
LOAD R2, 0
JMP done
greater:
LOAD R2, 1
done:
Function Calls
; Call a function
LOAD R0, 3000 ; Argument (30 degrees scaled)
CALL sin ; Call sin function
; Result in R0
PRINT R0
Coding Conventions
Naming
- Use descriptive labels:
loop,is_even,calculate_sum - Avoid single-letter labels except for very short functions
- Use underscores for multi-word labels:
my_function, notmyfunction
Comments
- Comment complex logic and algorithms
- Document function inputs/outputs
- Explain scaling factors for fixed-point arithmetic
- Note register usage conventions
Formatting
- Use consistent indentation (spaces or tabs)
- Align labels at the start of lines
- Add blank lines between logical sections
- Group related instructions together
Common Errors
Missing Operands
; ❌ Wrong
ADD R0
; ✅ Correct
ADD R0, R1
Wrong Operand Order
; ADD: reg1 = reg1 + reg2
; ❌ Wrong (if you want R0 = R0 + R1)
ADD R1, R0
; ✅ Correct
ADD R0, R1
Undefined Labels
; ❌ Wrong - label doesn't exist
JMP non_existent_label
; ✅ Correct - define label first
my_label:
LOAD R0, 10
JMP my_label
Related Documentation
- Instruction Set - All available instructions
- Registers & Memory - Understanding the register system
- Quick Start - Get started with examples