id: 3
title: Add and Subtract
subtitle: The power of three operands
description: Learn the ADD and SUB instructions

tutorial:
  - title: ADD — three-operand addition
    text: >
      ARM-style addition is neat: **three operands**! The first is the destination,
      the other two are the values being combined:
    code: |
      ADD R2, R0, R1    ; R2 = R0 + R1
      ADD R0, R0, #10   ; R0 = R0 + 10
  - title: SUB — subtraction
    text: >
      SUB works the same way, three operands:
    code: |
      SUB R2, R0, R1    ; R2 = R0 - R1
      SUB R0, R0, #5    ; R0 = R0 - 5
  - title: Why three operands?
    text: >
      You can drop the result straight into a new register, **no extra copy needed**!

goal: R0=**15**, R1=**27** — compute R0+R1 into **R2** (R0 and R1 unchanged)

initialState:
  registers:
    R0: 15
    R1: 27

testCases:
  - init: {}
    expected:
      registers:
        R0: 15
        R1: 27
        R2: 42

hints:
  - "First operand of ADD is the destination, the next two are added"
  - "ADD R2, R0, R1 — result goes in R2"
  - "Answer: ADD R2, R0, R1 / XHLT"

starThresholds: [2, 3, 5]

starterCode: |
  ; R0=15, R1=27
  ; Compute R0 + R1 into R2


  XHLT

showMemory: false
