Free to LearnSystems fieldbooksCode workshop
Fieldbooks/WebAssembly/Lesson 03
Lesson 03 of 08 · Course index

Lesson 03 / Stack & control

Which label receives the jump?

Trace a jump inside three nested regions. A block groups instructions, a loop gives them a place to repeat, and an if chooses a path. A zero chooses else. Each region supplies a label, a destination you can count outward from the current instruction. br 0 chooses the closest label.

+ Figure 03
Three nested regions, with depths 0, 1 and 2 counted from the inside.
From inside the else arm

1 · The big idea

WebAssembly has no arbitrary goto to random byte offsets—every jump targets a structured surrounding container (block, loop, or if) counted outward from the inside starting at depth 0. When if pops its condition off the stack, 0 chooses else; any non-zero value chooses then.

Each container pushes a control label onto a label stack. Here is the key difference between block and loop:

Jumping to a block or if exits forward past its end, so the jump must carry that block’s promised result types. Jumping to a loop jumps backward to the loop’s start, so it must carry the loop’s input parameter types.

2 · Worked step-by-step example

Step-by-step worked trace for lesson 3Counting Labels Outward From Inside else: 0=if, 1=loop, 2=blockDepth 0: ifexits to end of ifDepth 1: looprepeats start (0 params)Depth 2: blockexits needing [i32]Push i32.const 23 before br 2 to satisfy outer block exit [i32].
Worked Example: Counting Depths Inside block → loop → if/else
  1. Program: block (→ i32) { loop { i32.const 0; if { i32.const 12; br 2 } else { br 2 } } i32.const 99 }. Inside the else arm, count enclosing labels outward: 0 = if, 1 = loop, 2 = block (results: i32).
  2. br 1 would jump back to the start of loop (takes 0 inputs, loops forever).
  3. br 2 jumps past the outer block’s end, which promises [i32].
  4. With an empty stack at br 2, the verifier rejects! Pushing i32.const 23 before br 2 satisfies the outer block and skips i32.const 99.
Result: Depth 0 = innermost container; blocks/ifs check results on exit, while loops check params on repeat.

Read the case

Depth 0 · if → after its end

Depth 1 · loop → back to its start, carrying no inputs

Depth 2 · block → after its end, carrying one i32 result

3 · Bytecode stepper (explore before quizzing)

A branch to a block or if carries its result values to the exit. A branch to a loop carries its input values back to the beginning. This loop takes zero inputs. Its enclosing block returns one i32.

Bytecode is the list of machine instructions below. Step through Check types and Run values before answering the prediction below.

Instruction step
Ready0 / 8

Start with an empty stack. Read the instructions in order.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07br 2
  9. 08end
  10. 09end
  11. 10i32.const 99
  12. 11end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

block1 / 8

Open block at stack height 0.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07br 2
  9. 08end
  10. 09end
  11. 10i32.const 99
  12. 11end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

loop2 / 8

Open loop at stack height 0.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07br 2
  9. 08end
  10. 09end
  11. 10i32.const 99
  12. 11end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0loop h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

i32.const3 / 8

Push the type i32.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07br 2
  9. 08end
  10. 09end
  11. 10i32.const 99
  12. 11end

Operand stack top at right

i32

Control label stack innermost at right

function h=0block h=0loop h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

if4 / 8

Open if at stack height 0.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07br 2
  9. 08end
  10. 09end
  11. 10i32.const 99
  12. 11end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0loop h=0if h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

i32.const5 / 8

Push the type i32.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07br 2
  9. 08end
  10. 09end
  11. 10i32.const 99
  12. 11end

Operand stack top at right

i32

Control label stack innermost at right

function h=0block h=0loop h=0if h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

br6 / 8

Check the block target. Reset to entry height 0. This path cannot reach the next instruction.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07br 2
  9. 08end
  10. 09end
  11. 10i32.const 99
  12. 11end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0loop h=0if h=0 · unreachable

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

else7 / 8

Check the first arm. Start the other arm with the same input types.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07br 2
  9. 08end
  10. 09end
  11. 10i32.const 99
  12. 11end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0loop h=0else h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

br8 / 8

Stack underflow: i32 is missing at height 0.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07br 2
  9. 08end
  10. 09end
  11. 10i32.const 99
  12. 11end

Operand stack before rejection · top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0loop h=0else h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

Types rejected

Execution is blocked. Stack underflow: i32 is missing at height 0.

4 · Make a prediction

The else arm executes br 2 with an empty stack. What does its destination require?

Prediction confirmed. Count if, loop, block as depths 0, 1, 2. The outer block promises an i32 at its exit, so the jump must supply one.

Compare your prediction. The loop is depth 1 from inside else. br 2 counts one more label outward.

Compare your prediction. if already took the condition off the stack. The target block describes the value needed now.

5 · Repair the program

Make the zero condition leave the outer block with 23. Choose the replacement for the else arm.
Inspect this edit. The jump targets the loop start, which takes zero inputs. It discards 23 and repeats. The runner stops at its lab step limit.
Types acceptedRun pausedCalls 0Writes 0
Step through this edit
Instruction step
Ready0 / 13

Start with an empty stack. Read the instructions in order.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 1
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

block1 / 13

Open block at stack height 0.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 1
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

loop2 / 13

Open loop at stack height 0.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 1
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0loop h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

i32.const3 / 13

Push the type i32.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 1
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

i32

Control label stack innermost at right

function h=0block h=0loop h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

if4 / 13

Open if at stack height 0.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 1
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0loop h=0if h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

i32.const5 / 13

Push the type i32.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 1
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

i32

Control label stack innermost at right

function h=0block h=0loop h=0if h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

br6 / 13

Check the block target. Reset to entry height 0. This path cannot reach the next instruction.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 1
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0loop h=0if h=0 · unreachable

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

else7 / 13

Check the first arm. Start the other arm with the same input types.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 1
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0loop h=0else h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

i32.const8 / 13

Push the type i32.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 1
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

i32

Control label stack innermost at right

function h=0block h=0loop h=0else h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

br9 / 13

Check the loop target. Reset to entry height 0. This path cannot reach the next instruction.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 1
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0loop h=0else h=0 · unreachable

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

end10 / 13

Close this label. Restore its declared result types.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 1
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0loop h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

end11 / 13

Close this label. Restore its declared result types.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 1
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

i32.const12 / 13

Push the type i32.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 1
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

i32

Control label stack innermost at right

function h=0block h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

end13 / 13

Close this label. Restore its declared result types.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 1
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

i32

Control label stack innermost at right

function h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

Types accepted
Instruction step
Ready0 / 24

Start with an empty stack and one page of zero bytes.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 1
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
0065528
0065529
0065530
0065531
0065532
0065533
0065534
0065535
×65536+

Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.

block1 / 24

Enter the block body.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 1
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
0065528
0065529
0065530
0065531
0065532
0065533
0065534
0065535
×65536+

Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.

loop2 / 24

Enter the loop body.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 1
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0loop h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
0065528
0065529
0065530
0065531
0065532
0065533
0065534
0065535
×65536+

Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.

i32.const3 / 24

Push the value 0.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 1
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

i32 0

Control label stack innermost at right

function h=0block h=0loop h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
0065528
0065529
0065530
0065531
0065532
0065533
0065534
0065535
×65536+

Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.

if4 / 24

The condition is zero. Skip the first arm.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 1
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0loop h=0else h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
0065528
0065529
0065530
0065531
0065532
0065533
0065534
0065535
×65536+

Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.

i32.const5 / 24

Push the value 23.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 1
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

i32 23

Control label stack innermost at right

function h=0block h=0loop h=0else h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
0065528
0065529
0065530
0065531
0065532
0065533
0065534
0065535
×65536+

Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.

br6 / 24

Carry the loop inputs back to its first instruction.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 1
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0loop h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
0065528
0065529
0065530
0065531
0065532
0065533
0065534
0065535
×65536+

Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.

i32.const7 / 24

Push the value 0.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 1
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

i32 0

Control label stack innermost at right

function h=0block h=0loop h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
0065528
0065529
0065530
0065531
0065532
0065533
0065534
0065535
×65536+

Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.

if8 / 24

The condition is zero. Skip the first arm.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 1
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0loop h=0else h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
0065528
0065529
0065530
0065531
0065532
0065533
0065534
0065535
×65536+

Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.

i32.const9 / 24

Push the value 23.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 1
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

i32 23

Control label stack innermost at right

function h=0block h=0loop h=0else h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
0065528
0065529
0065530
0065531
0065532
0065533
0065534
0065535
×65536+

Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.

br10 / 24

Carry the loop inputs back to its first instruction.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 1
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0loop h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
0065528
0065529
0065530
0065531
0065532
0065533
0065534
0065535
×65536+

Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.

i32.const11 / 24

Push the value 0.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 1
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

i32 0

Control label stack innermost at right

function h=0block h=0loop h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
0065528
0065529
0065530
0065531
0065532
0065533
0065534
0065535
×65536+

Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.

if12 / 24

The condition is zero. Skip the first arm.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 1
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0loop h=0else h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
0065528
0065529
0065530
0065531
0065532
0065533
0065534
0065535
×65536+

Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.

i32.const13 / 24

Push the value 23.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 1
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

i32 23

Control label stack innermost at right

function h=0block h=0loop h=0else h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
0065528
0065529
0065530
0065531
0065532
0065533
0065534
0065535
×65536+

Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.

br14 / 24

Carry the loop inputs back to its first instruction.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 1
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0loop h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
0065528
0065529
0065530
0065531
0065532
0065533
0065534
0065535
×65536+

Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.

i32.const15 / 24

Push the value 0.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 1
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

i32 0

Control label stack innermost at right

function h=0block h=0loop h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
0065528
0065529
0065530
0065531
0065532
0065533
0065534
0065535
×65536+

Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.

if16 / 24

The condition is zero. Skip the first arm.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 1
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0loop h=0else h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
0065528
0065529
0065530
0065531
0065532
0065533
0065534
0065535
×65536+

Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.

i32.const17 / 24

Push the value 23.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 1
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

i32 23

Control label stack innermost at right

function h=0block h=0loop h=0else h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
0065528
0065529
0065530
0065531
0065532
0065533
0065534
0065535
×65536+

Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.

br18 / 24

Carry the loop inputs back to its first instruction.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 1
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0loop h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
0065528
0065529
0065530
0065531
0065532
0065533
0065534
0065535
×65536+

Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.

i32.const19 / 24

Push the value 0.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 1
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

i32 0

Control label stack innermost at right

function h=0block h=0loop h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
0065528
0065529
0065530
0065531
0065532
0065533
0065534
0065535
×65536+

Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.

if20 / 24

The condition is zero. Skip the first arm.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 1
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0loop h=0else h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
0065528
0065529
0065530
0065531
0065532
0065533
0065534
0065535
×65536+

Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.

i32.const21 / 24

Push the value 23.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 1
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

i32 23

Control label stack innermost at right

function h=0block h=0loop h=0else h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
0065528
0065529
0065530
0065531
0065532
0065533
0065534
0065535
×65536+

Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.

br22 / 24

Carry the loop inputs back to its first instruction.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 1
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0loop h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
0065528
0065529
0065530
0065531
0065532
0065533
0065534
0065535
×65536+

Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.

i32.const23 / 24

Push the value 0.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 1
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

i32 0

Control label stack innermost at right

function h=0block h=0loop h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
0065528
0065529
0065530
0065531
0065532
0065533
0065534
0065535
×65536+

Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.

if24 / 24

The condition is zero. Skip the first arm.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 1
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0loop h=0else h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
0065528
0065529
0065530
0065531
0065532
0065533
0065534
0065535
×65536+

Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.

End of displayed steps

The loop repeated. Showing the first 24 of 512 executed steps. The lab paused the run at its step limit.

Repair confirmed. The branch carries 23 out of the block. The runner skips the later 99 and finishes with 23.
Types acceptedRun finishedCalls 0Writes 0
Step through this edit
Instruction step
Ready0 / 13

Start with an empty stack. Read the instructions in order.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 2
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

block1 / 13

Open block at stack height 0.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 2
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

loop2 / 13

Open loop at stack height 0.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 2
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0loop h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

i32.const3 / 13

Push the type i32.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 2
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

i32

Control label stack innermost at right

function h=0block h=0loop h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

if4 / 13

Open if at stack height 0.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 2
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0loop h=0if h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

i32.const5 / 13

Push the type i32.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 2
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

i32

Control label stack innermost at right

function h=0block h=0loop h=0if h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

br6 / 13

Check the block target. Reset to entry height 0. This path cannot reach the next instruction.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 2
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0loop h=0if h=0 · unreachable

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

else7 / 13

Check the first arm. Start the other arm with the same input types.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 2
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0loop h=0else h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

i32.const8 / 13

Push the type i32.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 2
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

i32

Control label stack innermost at right

function h=0block h=0loop h=0else h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

br9 / 13

Check the block target. Reset to entry height 0. This path cannot reach the next instruction.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 2
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0loop h=0else h=0 · unreachable

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

end10 / 13

Close this label. Restore its declared result types.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 2
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0loop h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

end11 / 13

Close this label. Restore its declared result types.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 2
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

i32.const12 / 13

Push the type i32.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 2
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

i32

Control label stack innermost at right

function h=0block h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

end13 / 13

Close this label. Restore its declared result types.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 2
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

i32

Control label stack innermost at right

function h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

Types accepted
Instruction step
Ready0 / 6

Start with an empty stack and one page of zero bytes.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 2
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
0065528
0065529
0065530
0065531
0065532
0065533
0065534
0065535
×65536+

Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.

block1 / 6

Enter the block body.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 2
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
0065528
0065529
0065530
0065531
0065532
0065533
0065534
0065535
×65536+

Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.

loop2 / 6

Enter the loop body.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 2
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0loop h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
0065528
0065529
0065530
0065531
0065532
0065533
0065534
0065535
×65536+

Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.

i32.const3 / 6

Push the value 0.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 2
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

i32 0

Control label stack innermost at right

function h=0block h=0loop h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
0065528
0065529
0065530
0065531
0065532
0065533
0065534
0065535
×65536+

Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.

if4 / 6

The condition is zero. Skip the first arm.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 2
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0loop h=0else h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
0065528
0065529
0065530
0065531
0065532
0065533
0065534
0065535
×65536+

Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.

i32.const5 / 6

Push the value 23.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 2
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

i32 23

Control label stack innermost at right

function h=0block h=0loop h=0else h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
0065528
0065529
0065530
0065531
0065532
0065533
0065534
0065535
×65536+

Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.

br6 / 6

Carry the result values to the exit of this block.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i32.const 23
  9. 08br 2
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

i32 23

Control label stack innermost at right

function h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
0065528
0065529
0065530
0065531
0065532
0065533
0065534
0065535
×65536+

Each pair is one byte in base sixteen. The striped guard region marks addresses outside the page.

Run finished
Inspect this edit. The destination is correct. Its exit requires an i32, but the branch supplies an i64.
Types rejectedRun blockedCalls 0Writes 0
Step through this edit
Instruction step
Ready0 / 9

Start with an empty stack. Read the instructions in order.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i64.const 23
  9. 08br 2
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

block1 / 9

Open block at stack height 0.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i64.const 23
  9. 08br 2
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

loop2 / 9

Open loop at stack height 0.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i64.const 23
  9. 08br 2
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0loop h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

i32.const3 / 9

Push the type i32.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i64.const 23
  9. 08br 2
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

i32

Control label stack innermost at right

function h=0block h=0loop h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

if4 / 9

Open if at stack height 0.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i64.const 23
  9. 08br 2
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0loop h=0if h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

i32.const5 / 9

Push the type i32.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i64.const 23
  9. 08br 2
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

i32

Control label stack innermost at right

function h=0block h=0loop h=0if h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

br6 / 9

Check the block target. Reset to entry height 0. This path cannot reach the next instruction.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i64.const 23
  9. 08br 2
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0loop h=0if h=0 · unreachable

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

else7 / 9

Check the first arm. Start the other arm with the same input types.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i64.const 23
  9. 08br 2
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

[ ] Empty

Control label stack innermost at right

function h=0block h=0loop h=0else h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

i64.const8 / 9

Push the type i64.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i64.const 23
  9. 08br 2
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack top at right

i64

Control label stack innermost at right

function h=0block h=0loop h=0else h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

br9 / 9

Type mismatch: expected i32, found i64.

Bytecode instruction address

  1. 00block → i32
  2. 01loop
  3. 02i32.const 0
  4. 03if
  5. 04i32.const 12
  6. 05br 2
  7. 06else
  8. 07i64.const 23
  9. 08br 2
  10. 09end
  11. 10end
  12. 11i32.const 99
  13. 12end

Operand stack before rejection · top at right

i64

Control label stack innermost at right

function h=0block h=0loop h=0else h=0

Each label keeps its entry height (h = stack height when the block opened).

Linear memory

Tail of page 0
–65528
–65529
–65530
–65531
–65532
–65533
–65534
–65535
×65536+

Type checking does not read or write bytes.

Types rejected

Execution is blocked. Type mismatch: expected i32, found i64.

Code workshop

Implement labelArgs in my-rules.mjs. Find the branch destination and return its required types. A loop uses its inputs. An exit uses its results. The first command makes your own copy of the starter if needed. Edit the named function, then run the second command.

cp -n workshop/starter.mjs my-rules.mjs
node workshop/check.mjs 3 ./my-rules.mjs
Optional worked example in a separate file

Add a label selector. Store labels from outermost to innermost. Try depths 2 and 1 with the three labels from the sketch.

function target(labels, depth) {
  if (!Number.isInteger(depth) || depth < 0 || depth >= labels.length)
    throw Error("unknown label")
  return labels[labels.length - 1 - depth]
}
console.log(target(["block", "loop", "if"], 2))

Depth 2 returns block. Give each label its input and result lists. When you check a branch, use the loop’s inputs for a loop and the results for an exit.

Key Takeaway & Next Up

Structured branch depths count outward from 0; forward jumps carry exit results while backward loop jumps carry entry parameters.

Next: Next, we explore the exact boundary of unreachable stack checking when a block starts with data already on the stack.