Skip to main content

Crate lasm

Crate lasm 

Source
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 destination
  • ldr <reg>, [<reg>] - Load from memory address in register
  • str <reg>, [<reg>] - Store to memory address in register
  • load "var", <reg> - Load Rust variable into register
  • push <reg>, "var" - Store register value to Rust variable

§Arithmetic

  • add <dst>, <src> - Add
  • sub <dst>, <src> - Subtract
  • mul <dst>, <src> - Multiply
  • div <dst>, <src> - Divide
  • mod <dst>, <src> - Modulo

§Floating Point Arithmetic

  • fadd <dst>, <src> - Add floats
  • fsub <dst>, <src> - Subtract floats
  • fmul <dst>, <src> - Multiply floats
  • fdiv <dst>, <src> - Divide floats
  • fmod <dst>, <src> - Modulo floats

§Logic

  • and <dst>, <src> - Bitwise AND
  • or <dst>, <src> - Bitwise OR
  • xor <dst>, <src> - Bitwise XOR
  • not <dst> - Bitwise NOT
  • shl <dst>, <src> - Shift left
  • shr <dst>, <src> - Shift right

§Control Flow

  • cmp <left>, <right> - Compare values
  • beq <label> - Branch if equal
  • bne <label> - Branch if not equal
  • blt <label> - Branch if less than
  • bgt <label> - Branch if greater than
  • ble <label> - Branch if less or equal
  • bge <label> - Branch if greater or equal
  • jmp <label> - Unconditional jump
  • call <label> - Call subroutine
  • ret - Return from subroutine

§Stack Operations

  • pushr <reg> - Push register onto stack
  • popr <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 fd
  • syscall print_int - Print integer (r0)
  • syscall print_float - Print float (r0 as bits)
  • syscall print_str - Print null-terminated string (r0)
  • syscall flush - Flush output (r0 = fd)

§Memory

  • syscall malloc - Allocate memory (r0 = size, returns ptr in r0)
  • 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 whitespace
  • syscall isws - Check if string is all whitespace

§Conversion

  • syscall atoi - String -> integer
  • syscall atof - String -> float
  • syscall itoa - Integer -> string
  • syscall ftoa - Float -> string
  • syscall itof - Integer -> float
  • syscall ftoi - Float -> integer

§Time & Random

  • syscall time - Current time (ns, returns in r0)
  • 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 exit

Structs§

LasmFunction
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§

LasmError
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’

Functions§

call
Execute a compiled LasmFunction with the given variables.
compile
Compile LASM source code into a LasmFunction for JIT or AOT execution.