Exchange operations

The SWAP operations provide the ability to exchange stack items. There are 16 SWAP instructions available, and with each instruction, the stack items are removed and placed incrementally up to 17 items depending on the type of opcode used.

Mnemonic

Value

POP

PUSH

Gas

Description

SWAP1 . . . SWAP16

0x90 ...0x9f

X

Y

3

Used to swap the Nth stack item, where N is the number corresponding to the SWAP instruction used. X and Y are the items removed and placed on the stack, respectively.

Get Mastering Blockchain - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.