4. Emoji Math
Combine addition, subtraction, and multiplication as ordered steps.
Open this lesson →
1. Predict and trace
Before running the Try program, predict its output and trace the first three executed instructions. Track the relevant registers, flags or memory as needed. Then step the program to compare.
LOAD 10
ADD 5
PRINT
MUL 2
SUB 4
PRINT
HALT
Queue input: None
Initialize memory: All bytes initially zero
2. Build and check
Read one integer x and print (x + 5) × 2 − 4. Your program must work for every supplied input, including negative numbers.
Required instruction types: INPUT, ADD, MUL, SUB
Starter program
INPUT
# Calculate the expression in R0.
PRINT
HALT
Your program and notes
3. Explain the machine
Why is MUL after ADD necessary for (x+5)×2−4?
5. Division and Remainders
Explain floor division and signed remainder, including negatives.
Open this lesson →
1. Predict and trace
Before running the Try program, predict its output and trace the first three executed instructions. Track the relevant registers, flags or memory as needed. Then step the program to compare.
LOAD -9 R1
LOAD R1
DIV 4
PRINT
LOAD R1
MOD 4
PRINT
HALT
Queue input: None
Initialize memory: All bytes initially zero
2. Build and check
Read an integer. Print its floor quotient by 4, then its signed remainder by 4. Keep the original long enough to calculate both.
Required instruction types: INPUT, DIV, MOD, COPY
Starter program
INPUT
COPY R0 R1
# Print quotient, restore the input, then print remainder.
HALT
Your program and notes
3. Explain the machine
Why save the original input before calculating the quotient?
6. A Two-input Calculator
Build a reusable calculator instead of a fixed answer.
Open this lesson →
1. Predict and trace
Before running the Try program, predict its output and trace the first three executed instructions. Track the relevant registers, flags or memory as needed. Then step the program to compare.
INPUT
COPY R0 R1
INPUT
COPY R0 R2
LOAD R1
ADD R2
PRINT
LOAD R1
MUL R2
PRINT
HALT
Queue input: 3, 4
Initialize memory: All bytes initially zero
2. Build and check
Read integers a and b. Print their sum and then their product. Use the supplied values rather than fixed answers.
Required instruction types: INPUT, ADD, MUL
Starter program
INPUT
COPY R0 R1
INPUT
COPY R0 R2
# Use R1 and R2 twice.
HALT
Your program and notes
3. Explain the machine
What mistake occurs if you multiply immediately after printing the sum?