Expand description
§LASM - Lucia Assembly Language Documentation
This is the documentation for LASM language.
§Registers
- General Purpose:
r0-r15(64-bit) - Stack Pointer:
rsp - Base Pointer:
rbp
§Instructions
§Data Movement
mov <src>, <dst>- Move value from source to destinationldr <reg>, [<reg>]- Load from memory address in registerstr <reg>, [<reg>]- Store to memory address in registerload "var", <reg>- Load Rust variable into registerpush <reg>, "var"- Store register value to Rust variable
§Arithmetic
add <dst>, <src>- Addsub <dst>, <src>- Subtractmul <dst>, <src>- Multiplydiv <dst>, <src>- Dividemod <dst>, <src>- Modulo
§Floating Point Arithmetic
fadd <dst>, <src>- Add floatsfsub <dst>, <src>- Subtract floatsfmul <dst>, <src>- Multiply floatsfdiv <dst>, <src>- Divide floatsfmod <dst>, <src>- Modulo floats
§Logic
and <dst>, <src>- Bitwise ANDor <dst>, <src>- Bitwise ORxor <dst>, <src>- Bitwise XORnot <dst>- Bitwise NOTshl <dst>, <src>- Shift leftshr <dst>, <src>- Shift right
§Control Flow
cmp <left>, <right>- Compare valuesbeq <label>- Branch if equalbne <label>- Branch if not equalblt <label>- Branch if less thanbgt <label>- Branch if greater thanble <label>- Branch if less or equalbge <label>- Branch if greater or equaljmp <label>- Unconditional jumpcall <label>- Call subroutineret- Return from subroutine
§Stack Operations
pushr <reg>- Push register onto stackpopr <reg>- Pop from stack into register
§Operands
- Immediate values: Numbers (e.g.,
42) or strings (e.g.,"hello") - Registers:
r0-r15 - Labels: For jumps and calls
§Syscalls
§I/O
syscall write- Write to fd (r0= fd,r1= buffer,r2= count)syscall read- Read from fdsyscall print_int- Print integer (r0)syscall print_float- Print float (r0as bits)syscall print_str- Print null-terminated string (r0)syscall flush- Flush output (r0= fd)
§Memory
syscall malloc- Allocate memory (r0= size, returns ptr inr0)syscall free- Free memory (r0= ptr)syscall memcpy- Copy memory (r0= dst,r1= src,r2= len)syscall memset- Set memory (r0= dst,r1= val,r2= len)
§Strings
syscall strcmp- Compare strings (r0= str1,r1= str2)syscall strcpy- Copy string (r0= dst,r1= src)syscall strlen- Get string length (r0= str)syscall starts_with- Check prefix (r0= str,r1= prefix)syscall streq- Check equality (r0= str1,r1= str2)syscall ends_with- Check suffix (r0= str,r1= suffix)syscall trim/trim_start/trim_end- Trim whitespacesyscall isws- Check if string is all whitespace
§Conversion
syscall atoi- String -> integersyscall atof- String -> floatsyscall itoa- Integer -> stringsyscall ftoa- Float -> stringsyscall itof- Integer -> floatsyscall ftoi- Float -> integer
§Time & Random
syscall time- Current time (ns, returns inr0)syscall fmt_time- Format time (r0= total_nanos,r1= format,r2= buffer)syscall rand- Generate random float (r0= seed)
§Utilities
syscall sleep- Sleep (r0= ms)syscall system- Execute command (r0= command string)
§System
syscall exit- Exit program (r0= status)
§Syntax Details
- Comments: Start with
; - Labels: End with
: - Strings: Double quotes, null-terminated automatically
- Numbers: Decimal integers, can be used as immediates
- Case Sensitive: Keywords and registers
§Examples
§Hello World
mov "Hello, World!\n", r1
mov 1, r0
mov 14, r2
syscall write
mov 0, r0
syscall exit§Calculator
mov 10, r0
mov 20, r1
add r0, r1
syscall print_int
mov "\n", r1
mov 1, r0
mov 1, r2
syscall write
mov 0, r0
syscall exitStructs§
- Lasm
Function - Represents a compiled LASM function, containing the JIT-compiled code and variable information. The internal structure varies based on the compilation target (LLVM or Cranelift) and whether debug features are enabled.
- Location
- Location information for errors
Enums§
- Lasm
Error - Error type for LASM
- Target
- Target architecture and platform for LASM compilation. Currently only Native is supported
- Value
- Represents a value that can be passed to or returned from a LASM function.
Constants§
- USES_
CRANELIFT - Constant to indicate if ‘lucia-lasm’ was compiled with Cranelift support
- USES_
DEBUG - Constant to indicate if ‘lucia-lasm’ was compiled with debug features enabled
- USES_
LLVM - Constant to indicate if ‘lucia-lasm’ was compiled with LLVM support
- VERSION
- Constant for the current version of ‘lucia-lasm’