What is a "Step"?
A step is the execution of a single Romasm instruction by the Virtual Machine.
Example:
This program takes 3 steps to execute.
Each instruction type takes exactly 1 step, regardless of complexity:
LOAD R0, 10= 1 stepADD R0, R1= 1 stepCALL sin= 1 step (but the sin function itself takes many steps)JMP loop= 1 step
Why Do We Have Step Limits?
Safety First!
Step limits prevent infinite loops from freezing your browser.
Without limits, a buggy program like this would run forever:
This would freeze your browser tab, requiring you to force-close it.
Default Limits:
- Regular scripts: 10,000 steps
- Plotting scripts: 50,000 steps
- Plotting with trig functions: 200,000 steps
How Many Steps Do Programs Take?
Simple Programs:
- Basic arithmetic: 5-10 steps
- Factorial of 5: ~50 steps
- Fibonacci sequence (10 numbers): ~100 steps
Complex Programs:
- Sine function call: ~100-200 steps (includes reduction loops, Taylor series)
- Plotting sine wave (41 points): ~8,000-16,000 steps
- Large loops with function calls: Can easily exceed 10,000 steps
Why Plotting Takes So Many Steps:
When plotting a sine wave:
- Loop runs 41 iterations (one per point)
- Each iteration calls
CALL sin - Each sin call does:
- Angle reduction (multiple loops)
- Taylor series calculation (many operations)
- Scaling and conversion
- Each iteration also does PRINT (output coordinates)
Total: 41 × ~200 steps = ~8,200 steps minimum
With overhead, it can easily reach 15,000+ steps!
Chunked Execution
For plotting scripts, Romasm uses chunked execution:
- Executes in chunks of 5,000-10,000 steps
- Yields to the browser between chunks (prevents freezing)
- Allows UI updates during long-running scripts
- Total limit: 100,000-200,000 steps for plotting
How It Works:
- Execute 5,000 steps
- Yield to browser (allows UI updates)
- Continue with next 5,000 steps
- Repeat until program completes or limit reached
What Happens When the Limit is Reached?
If a program exceeds the step limit:
- Execution stops immediately
- A warning message is displayed
- Any output generated so far is shown
- The browser remains responsive (doesn't freeze)
Example Warning:
This means the program was stopped at the limit, but you can see what it computed so far.
Optimizing Your Programs
To reduce step counts:
- Use larger step sizes in loops (fewer iterations)
- Avoid nested loops when possible
- Simplify calculations (use approximations for plotting)
- Break large programs into smaller functions
Example: Optimized Sine Wave Plotting
Before: Step size 20 (0.2 units) = 101 iterations = ~20,000 steps
After: Step size 50 (0.5 units) = 41 iterations = ~8,000 steps
Still smooth enough for visualization, but much faster!
Related Documentation
- Virtual Machine - VM architecture details
- Instruction Set - All available instructions
- Trigonometric Functions - Why sin/cos take many steps