Memory System

Understanding Romasm's memory addressing and storage

Overview

Romasm uses a sparse memory system where you can store and retrieve values at specific addresses. Memory is accessed using square bracket notation [address].

Memory Addressing

Syntax

Access memory using square brackets:

LOAD R0, [100]    ; Load from memory address 100
STORE R1, [200]   ; Store to memory address 200

Addresses

  • Memory addresses are integers (0, 1, 2, 3, ...)
  • No upper limit (limited only by available memory)
  • Addresses can be immediate values or stored in registers

Memory Characteristics

Sparse Allocation

Memory is sparse - only accessed addresses are allocated:

  • If you never access address 5000, it doesn't exist
  • Memory is allocated on-demand
  • Uninitialized memory returns 0

Persistence

Memory persists for the duration of program execution:

  • Values remain until overwritten
  • Memory is cleared when a new program is loaded
  • Each program execution starts with fresh memory

Examples

Basic Memory Operations

; Store and retrieve values
LOAD R0, 42
STORE R0, [100]    ; Store 42 to address 100
LOAD R1, [100]     ; Load from address 100
PRINT R1           ; Output: 42

Array-Like Storage

; Store multiple values
LOAD R0, 10
STORE R0, [0]      ; array[0] = 10
LOAD R0, 20
STORE R0, [1]      ; array[1] = 20
LOAD R0, 30
STORE R0, [2]      ; array[2] = 30

; Retrieve values
LOAD R1, [0]       ; R1 = array[0] = 10
LOAD R2, [1]       ; R2 = array[1] = 20

Using Registers for Addresses

; Calculate address dynamically
LOAD R0, 100       ; Base address
LOAD R1, 5         ; Index
ADD R0, R1         ; R0 = 100 + 5 = 105
LOAD R2, 42
STORE R2, [R0]     ; Store to address 105

Note: Register-based addressing may require special handling depending on the assembler implementation.

Memory Visualization

In the Romasm IDE, you can view memory contents:

  • See all allocated memory addresses
  • View values stored at each address
  • Track memory changes during execution
  • Debug memory-related issues

Best Practices

Memory Management

  • Use consistent address ranges for related data
  • Document what each address stores
  • Consider using offsets for arrays (e.g., [100], [101], [102])
  • Be mindful of memory usage for large programs

Related Documentation