local.tee
Pops a value off the stack and sets a variable's value with it, and pushes the value back onto the stack. This functions just like the local.set instruction but it keeps the value on the stack.

Syntax

local.tee $label

Parameters

$label
The label name of the local variable. This can also be the index of the local variable. The variable will be set to the value on the stack. The value on the stack must be the same data type as the variable.

Stack In

* The value to be stored in the local variable. The data type must be the same as the variable used.

Stack Out

* The same value that was stored on the stack before the instruction.

Example

;; Example function
(func $example
    ;; Create local variable
    (local $age i32)
    
    ;; Set $age local variable
    i32.const 42
    local.tee $age

    ;; The stack still contains the i32 value of 42
)