This page is a placeholder. All examples on this page are currently AI-generated and are not correct. This documentation will be completed in the future with accurate, tested examples.
Overview
Opcode:0x8FIntroduced: Frontier (EVM genesis)DUP16 duplicates the 16th stack item and pushes it to the top of the stack. The original 16th item remains in place.
Specification
Stack Input:
[..., value, item15, ..., item1]
Stack Output:
[..., value, item15, ..., item1, value]
Gas Cost: 3 (GasFastestStep)Operation:
value = stack[depth - 16]stack.push(value)
Behavior
DUP16 copies the 16th-from-top stack item without removing it. Requires stack depth ≥ 16.Key characteristics:
contract Example { function deepAccess() public pure { // Access deep stack value assembly { // Stack has 16 items dup16 // Duplicate 16th item to top } }}
Cost: 3 gas (GasFastestStep)All DUP1-16 operations cost the same despite different stack depths accessed.Comparison:
Operation
Gas
Note
DUP16
3
Duplicate 16th item
PUSH1-32
3
Same cost tier
POP
2
Cheaper
Common Usage
Deep Stack Access
function complex() public pure { assembly { // Build deep stack let v1 := 1 let v2 := 2 let v3 := 3 let v4 := 4 let v5 := 5 let v6 := 6 let v7 := 7 let v8 := 8 let v9 := 9 let v10 := 10 let v11 := 11 let v12 := 12 let v13 := 13 let v14 := 14 let v15 := 15 let v16 := 16 // Access v1 from depth 16 dup16 }}```### Efficient Copies```solidity// Instead of multiple loadsassembly { let value := sload(slot) // Expensive // Use value let value2 := sload(slot) // Wasteful!}// Use DUP to reuseassembly { let value := sload(slot) // Load once dup1 // Copy // Use both copies}
Conditional Logic
assembly { let condition := calldataload(0) dup1 // Keep condition for later iszero jumpi(skip) // Use condition again skip:}