← All lessons

Byte Memory · Lesson 9 of 30 · about 9 minutes

Bytes and Boundaries

See why memory wraps while registers do not.

01 / Explain

Understand the idea

A byte has 256 possible values, 0 through 255. STORE keeps the low eight bits of a number: 256 becomes 0, −1 becomes 255, and 511 becomes 255. This is the documented value & 255 rule.

Registers keep safe integer arithmetic. LOAD 256 still places 256 in R0; only storing it into byte memory changes its representation. The overflow flag reports a signed 32-bit boundary without automatically wrapping arithmetic.

02 / Try

Watch it happen

Expect 256, 0, 255. Address 255 is valid; address 256 is not.

LOAD 256
PRINT
STORE 255
LOAD [255]
PRINT
LOAD -1
STORE 255
LOAD [255]
PRINT
HALT

Use Step to follow one instruction at a time. You can change the example and replay it.

03 / Challenge

Make it work

Read an integer, store it at address 255, retrieve the resulting byte, and print it. Do not calculate a substitute fixed answer.

The checker runs your current editor program in a fresh machine for each of 4 test cases. It supplies inputs and seeded memory itself; the lab’s current output and memory do not decide your result.

INPUT
# Store at the final valid address, then read back.
HALT
Need a hint?

The CPU’s STORE instruction already performs byte conversion.

Reveal a worked solution

Read the program, predict each instruction’s effect, then step through it in the lab.

INPUT
STORE 255
LOAD [255]
PRINT
HALT

Emoji CPU lab

Ready · 0 cycles

Emoji program

Type LOAD, ADD, or another opcode then Space to insert emoji. Ctrl/⌘ + Enter runs or pauses; Escape pauses; Ctrl/⌘ + ] indents. Tab moves focus. Labels use a colon. Jumps use zero-based instruction addresses.

Instruction map and breakpoints (0)

Breakpoints stop before an instruction. Run resumes past the stopped breakpoint once; Step executes it directly. Editing source clears old breakpoints and machine state.

    CPU registers

    R0
    0
    R1
    0
    R2
    0
    R3
    0
    R4
    0
    R5
    0
    R6
    0
    R7
    0
    Program counter (PC)
    0
    Stack pointer (SP)
    255
    Flags
    Zero: off · Negative: off · Overflow: off
    Delay request
    0 ms
    Stacks and loop frames

    SP = 255 − data depth − call depth. The stack is separate from memory.

    Data stack (bottom → top)

    Empty

    Call return addresses (bottom → top)

    Empty

    Loop frames

    Empty

    Output and input

    Run a PRINT instruction to see output.

    Queued input: Empty

    Memory · 256 bytes · 0 nonzero

    Each cell shows address:value. R = read this step; W = written this step. Select a cell to inspect or initialize it before execution. Use arrow keys to move, Home/End for the row, and Ctrl/⌘ + Home/End for the whole memory.

    Reset before initializing memory. Stored values wrap to 0–255.
    Execution trace · 0 entries

    Recent entries below. Inspect any zero-based index to see complete detached before/after state.

    Check your challenge

    You can run this check any time. Every case must pass to record completion.

    Progress uses localStorage only. It stays on this browser and is never sent to a server.