Overview
The Romasm Linker (linker/romasm-linker.js) combines user-written Romasm code with standard library functions, allowing you to call functions like sin, cos, sqrt without copying their code.
How It Works
Step 1: Load Standard Library
The linker loads and assembles stdlib files:
stdlib/trig.romasm- Trigonometric functionsstdlib/math.romasm- Basic math functionsstdlib/calculus.romasm- Calculus functionsstdlib/advanced-math.romasm- Advanced mathstdlib/sine-taylor.romasm- High-precision sine
It extracts function labels (like sin:, cos:) and records their addresses.
Step 2: Assemble User Code
Your Romasm code is assembled normally. When you write CALL sin, the assembler creates an unresolved label reference:
{
opcode: 'CA',
operands: [{
type: 'label',
value: 0, // Placeholder
labelName: 'sin' // Function name for linker
}]
}
Step 3: Link Functions
The linker:
- Combines stdlib instructions with user instructions
- Resolves
CALL sinto the actual stdlib function address - Creates a function map for reference
; Before linking:
CALL sin ; Unresolved, value = 0
; After linking:
CALL sin ; Resolved to stdlib address, e.g., value = 42
Using the Linker
In the Calculator
The linker is automatically used when you call stdlib functions. Just write:
LOAD R0, 3000
CALL sin
PRINT R0
The calculator engine handles linking automatically.
In the IDE
You may need to manually enable stdlib linking, or include stdlib code directly in your program.
Function Resolution
When the linker encounters CALL function_name:
- It checks if
function_nameexists in the stdlib - If found, replaces the placeholder address with the real address
- If not found, logs a warning (but doesn't fail - in case it's a user-defined function)
Available Functions
Functions available through the linker include:
- Math:
factorial,power,sqrt - Trig:
sin,cos - Calculus:
derivative_x_squared,integral_x_squared, etc. - Advanced:
exp,ln
See the Standard Library documentation for complete lists.
Related Documentation
- Assembler - How code is assembled
- Standard Library - Math - Available functions
- Standard Library - Trigonometry - Trig functions