Try, inspect, change

Twenty worked examples

Load an example into the lab, step through its instructions, then change a value. Each example includes its expected output.

Hello World

Your first emoji program! Loads a number and prints it.

beginner · basics

📥 42
🖨️
⏹️

Simple Addition

Add two numbers together.

beginner · basics

📥 10
➕ 5
🖨️
⏹️

Mini Calculator

Perform multiple arithmetic operations.

beginner · basics

📥 100
➕ 50
🖨️
➖ 30
🖨️
✖️ 2
🖨️
➗ 4
🖨️
⏹️

Output: 150, 120, 240, 60

Open Mini Calculator →

Countdown Timer

Count down from 10 to 1 using a loop.

beginner · basics

LOAD 10
again: PRINT
SUB 1
JUMP_IF_ZERO done
JUMP again
done: HALT

Output: 10, 9, 8, 7, 6, 5, 4, 3, 2, 1

Open Countdown Timer →

Fibonacci Sequence

Generate eight Fibonacci values with registers and a bounded loop.

intermediate · algorithms

LOAD 1 R1
LOAD 1 R2
LOOP 8
LOAD R1
PRINT
COPY R0 R3
ADD R2
COPY R2 R1
COPY R0 R2
RETURN
HALT

Output: 1, 1, 2, 3, 5, 8, 13, 21

Open Fibonacci Sequence →

Powers of Two

Print 2⁰ through 2⁷: 1, 2, 4, 8, 16, 32, 64, 128.

intermediate · algorithms

📥 1
🖨️
✖️ 2
🖨️
✖️ 2
🖨️
✖️ 2
🖨️
✖️ 2
🖨️
✖️ 2
🖨️
✖️ 2
🖨️
✖️ 2
🖨️
⏹️

Output: 1, 2, 4, 8, 16, 32, 64, 128

Open Powers of Two →

Memory Operations

Store two bytes, clear R0, then actually read them from memory.

intermediate · basics

LOAD 42
STORE 0
LOAD 99
STORE 1
LOAD 0
LOAD [0]
PRINT
LOAD [1]
PRINT
HALT

Even or Odd

Check if a number is even or odd using MOD.

intermediate · algorithms

📥 7
📊 2
🖨️
📥 8
📊 2
🖨️
⏹️

Stack Operations

Push and pop values on the stack.

advanced · advanced

📥 10
⬆️
📥 20
⬆️
📥 30
⬆️
⬇️
🖨️
⬇️
🖨️
⬇️
🖨️
⏹️

Output: 30, 20, 10

Open Stack Operations →

Bitwise Magic

Demonstrate AND, OR, XOR operations.

advanced · advanced


📥 12
🔀 10
🖨️
📥 12
🔃 3
🖨️
📥 12
🔄 15
🖨️
📥 255
❌
🖨️
⏹️

Output: 8, 15, 3, -256

Open Bitwise Magic →

Sum 1 to N

Calculate the sum of numbers from 1 to 10.

beginner · algorithms

LOAD 1 R1
LOAD 0 R2
LOOP 10
LOAD R2
ADD R1
COPY R0 R2
LOAD R1
ADD 1
COPY R0 R1
RETURN
LOAD R2
PRINT
HALT

Factorial Calculator

Calculate 5! (5 factorial = 120) using a loop.

intermediate · algorithms

LOAD 5 R1
LOAD 1 R2
LOOP 5
LOAD R2
MUL R1
COPY R0 R2
LOAD R1
SUB 1
COPY R0 R1
RETURN
LOAD R2
PRINT
HALT

Maximum of Two Numbers

Choose the larger of two small nonnegative integers using a signed 32-bit sign mask.

beginner · basics

LOAD 15 R1
LOAD 25 R2
LOAD R1
SUB R2
AND -2147483648
JUMP_IF_ZERO first
LOAD R2
JUMP show
first: LOAD R1
show: PRINT
HALT

Swap Two Values

Swap values between R1 and R2 using the stack.

beginner · basics


📥 10
📋 R0 R1
📥 20
📋 R0 R2
📥 R1
🖨️
📥 R2
🖨️
📥 R1
⬆️
📥 R2
📋 R0 R1
⬇️
📋 R0 R2
📥 R1
🖨️
📥 R2
🖨️
⏹️

Output: 10, 20, 20, 10

Open Swap Two Values →

Absolute Value

Find the absolute value of a small signed 32-bit integer with a sign mask.

beginner · algorithms

LOAD -42 R1
LOAD R1
AND -2147483648
JUMP_IF_ZERO positive
LOAD R1
MUL -1
JUMP show
positive: LOAD R1
show: PRINT
HALT

Count Down Then Up

Count from 3 to 1, then 1 to 3.

beginner · basics


📥 3
🖨️
➖ 1
❓ 5
⏭️ 1
📥 1
🖨️
➕ 1
⚖️ 4
❓ 11
⏭️ 6
⏹️

Output: 3, 2, 1, 1, 2, 3

Open Count Down Then Up →

Multiply by Bit Shifting

Double 7 twice using addition, equivalent to multiplying by 4.

intermediate · advanced


📥 7
📋 R0 R1
📥 R1
➕ R1
📋 R0 R1
📥 R1
➕ R1
📋 R0 R1
📥 R1
🖨️
⏹️

Triangle Numbers

Print first 5 triangle numbers: 1, 3, 6, 10, 15.

intermediate · algorithms

LOAD 0 R2
LOAD 1 R1
LOOP 5
LOAD R2
ADD R1
COPY R0 R2
PRINT
LOAD R1
ADD 1
COPY R0 R1
RETURN
HALT

Output: 1, 3, 6, 10, 15

Open Triangle Numbers →

Register Cascade

Copy a value through all 8 registers.

intermediate · advanced


📥 42
📋 R0 R1
📋 R1 R2
📋 R2 R3
📋 R3 R4
📋 R4 R5
📋 R5 R6
📋 R6 R7
📥 R7
🖨️
⏹️