Skip to main content
Be Bitwise

Memory Read & Write

Store a value to a memory address and read it back. Understand how LOAD and STORE work with memory.

Registers are fast but scarce — a CPU might only have 8 of them. Main memory (RAM) is where most data lives. STORE writes a register value to a memory address, and LOAD reads a value from memory into a register. The address is itself held in a register, making it possible to compute addresses at runtime. This register-to-memory transfer pattern is fundamental to how programs manage data.

Simulator

Loading simulator...

Walkthrough Guide

  1. 1

    Set up the value and address

    Do this: Step through both MOV instructions

    Watch for: R0 = 42 (value to store), R1 = 128 (target memory address, 0x80)

    R0 holds the data we want to store. R1 holds the memory address where we will store it. The CPU treats both as plain numbers — context determines which is a value and which is an address.

  2. 2

    Write to memory

    Do this: Step through STORE [R1], R0

    Watch for: Value 42 appears at address 128 in the memory grid

    STORE [R1], R0 reads the address from R1 (128), reads the value from R0 (42), and writes that value to memory at address 128. The square brackets around R1 mean 'the address held in R1'.

  3. 3

    Clear the source register

    Do this: Step through MOV R0, #0

    Watch for: R0 changes from 42 to 0. The value in memory at address 128 is unaffected

    We zero out R0 to prove that the upcoming LOAD actually reads from memory, not from R0. Memory is independent of registers — changing a register does not change what is stored in memory.

  4. 4

    Read back from memory

    Do this: Step through LOAD R2, [R1]

    Watch for: R2 changes from 0 to 42, copied from memory address 128

    LOAD R2, [R1] reads the address from R1 (128), fetches the value at memory[128] (42), and writes it into R2. Even though R0 was cleared, the value persists in memory until something overwrites it.

Objectives

  • •See 42 appear in the memory grid at address 128
  • •Watch R0 get cleared to 0
  • •See LOAD copy the value from memory back into R2
  • •R2 should equal 42 at the end

Hints

  • Watch the memory grid - the stored value will highlight at the target address