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:0x9EIntroduced: Frontier (EVM genesis)SWAP15 exchanges the top stack item with the 16th item from the top. Only these two positions change - all other items remain in place.
Cost: 3 gas (GasFastestStep)All SWAP1-16 operations cost the same despite different stack depths accessed.Comparison:
Operation
Gas
Note
SWAP15
3
Swap with 16th item
DUP1-16
3
Same cost tier
POP
2
Cheaper
Common Usage
Deep Stack Manipulation
function complex() public pure { assembly { let v0 := 0 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 // Need v0 at top swap15 // v0 now at top }}```### Efficient Reordering```solidity// Reorder for function callassembly { // Have: [value, to, token] // Need: [token, to, value] swap2 // [token, to, value] // Call transfer(token, to, value) call(gas(), target, 0, 0, 100, 0, 0)}
Storage Optimization
assembly { let slot := 0 let value := 42 // Stack: [slot, value] // SSTORE needs (slot, value) but we have them reversed // No swap needed in this case, but if we did: swap1 // Stack: [value, slot] sstore}