Stack Manipulation
Here 0 <= i,j,k <= 15
if not stated otherwise.
TVM Instructions Content List
- Overview
- Stack Manipulation
- Tuple, List and Null
- Constants and Literals
- Arithmetic Operations
- Data Comparison
- Cell Manipulation
- Continuation and Control Flow
- Exception Generation and Handling
- Dictionary Manipulation
- Application-specific Primitives
- Miscellaneous
Opcode | Fift syntax | Stack | Description | Gas |
---|---|---|---|---|
Please enter a search query | ||||
No results found |
Basic stack manipulation primitives
xxxxxxx Opcode | xxxxxxxxxxxxxxxxxxxxxxxxxxxx Fift syntax | xxxxxxxxxxxxxxxxx Stack | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Description | xxxx Gas |
---|---|---|---|---|
00 | NOP | - | Does nothing. | 18 |
01 | SWAP | x y - y x | Same as s1 XCHG0 . | 18 |
0i | s[i] XCHG0 | Interchanges s0 with s[i] , 1 <= i <= 15 . | 18 | |
10ij | s[i] s[j] XCHG | Interchanges s[i] with s[j] , 1 <= i < j <= 15 . | 26 | |
11ii | s0 [ii] s() XCHG | Interchanges s0 with s[ii] , 0 <= ii <= 255 . | 26 | |
1i | s1 s[i] XCHG | Interchanges s1 with s[i] , 2 <= i <= 15 . | 18 | |
2i | s[i] PUSH | Pushes a copy of the old s[i] into the stack. | 18 | |
20 | DUP | x - x x | Same as s0 PUSH . | 18 |
21 | OVER | x y - x y x | Same as s1 PUSH . | 18 |
3i | s[i] POP | Pops the old s0 value into the old s[i] . Equivalent to s[i] XCHG0 DROP | 18 | |
30 | DROP | x - | Same as s0 POP , discards the top-of-stack value. | 18 |
31 | NIP | x y - y | Same as s1 POP . | 18 |
Complex stack manipulation
xxxxxxx Opcode | xxxxxxxxxxxxxxxxxxxxxxxxxxxx Fift syntax | xxxxxxxxxxxxxxxxx Stack | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Description | xxxx Gas |
---|---|---|---|---|
4ijk | s[i] s[j] s[k] XCHG3 | Equivalent to s2 s[i] XCHG s1 s[j] XCHG s[k] XCHG0 . | 26 | |
50ij | s[i] s[j] XCHG2 | Equivalent to s1 s[i] XCHG s[j] XCHG0 . | 26 | |
51ij | s[i] s[j] XCPU | Equivalent to s[i] XCHG0 s[j] PUSH . | 26 | |
52ij | s[i] s[j-1] PUXC | Equivalent to s[i] PUSH SWAP s[j] XCHG0 . | 26 | |
53ij | s[i] s[j] PUSH2 | Equivalent to s[i] PUSH s[j+1] PUSH . | 26 | |
540ijk | s[i] s[j] s[k] XCHG3_l | Long form of XCHG3 . | 34 | |
541ijk | s[i] s[j] s[k] XC2PU | Equivalent to s[i] s[j] XCHG2 s[k] PUSH . | 34 | |
542ijk | s[i] s[j] s[k-1] XCPUXC | Equivalent to s1 s[i] XCHG s[j] s[k-1] PUXC . | 34 | |
543ijk | s[i] s[j] s[k] XCPU2 | Equivalent to s[i] XCHG0 s[j] s[k] PUSH2 . | 34 | |
544ijk | s[i] s[j-1] s[k-1] PUXC2 | Equivalent to s[i] PUSH s2 XCHG0 s[j] s[k] XCHG2 . | 34 | |
545ijk | s[i] s[j-1] s[k-1] PUXCPU | Equivalent to s[i] s[j-1] PUXC s[k] PUSH . | 34 | |
546ijk | s[i] s[j-1] s[k-2] PU2XC | Equivalent to s[i] PUSH SWAP s[j] s[k-1] PUXC . | 34 | |
547ijk | s[i] s[j] s[k] PUSH3 | Equivalent to s[i] PUSH s[j+1] s[k+1] PUSH2 . | 34 | |
55ij | [i+1] [j+1] BLKSWAP | Permutes two blocks s[j+i+1] … s[j+1] and s[j] … s0 .0 <= i,j <= 15 Equivalent to [i+1] [j+1] REVERSE [j+1] 0 REVERSE [i+j+2] 0 REVERSE . | 26 | |
5513 | ROT2 2ROT | a b c d e f - c d e f a b | Rotates the three topmost pairs of stack entries. | 26 |
550i | [i+1] ROLL | Rotates the top i+1 stack entries.Equivalent to 1 [i+1] BLKSWAP . | 26 | |
55i0 | [i+1] -ROLL [i+1] ROLLREV | Rotates the top i+1 stack entries in the other direction.Equivalent to [i+1] 1 BLKSWAP . | 26 | |
56ii | [ii] s() PUSH | Pushes a copy of the old s[ii] into the stack.0 <= ii <= 255 | 26 | |
57ii | [ii] s() POP | Pops the old s0 value into the old s[ii] .0 <= ii <= 255 | 26 | |
58 | ROT | a b c - b c a | Equivalent to 1 2 BLKSWAP or to s2 s1 XCHG2 . | 18 |
59 | ROTREV -ROT | a b c - c a b | Equivalent to 2 1 BLKSWAP or to s2 s2 XCHG2 . | 18 |
5A | SWAP2 2SWAP | a b c d - c d a b | Equivalent to 2 2 BLKSWAP or to s3 s2 XCHG2 . | 18 |
5B | DROP2 2DROP | a b - | Equivalent to DROP DROP . | 18 |
5C | DUP2 2DUP | a b - a b a b | Equivalent to s1 s0 PUSH2 . | 18 |
5D | OVER2 2OVER | a b c d - a b c d a b | Equivalent to s3 s2 PUSH2 . | 18 |
5Eij | [i+2] [j] REVERSE | Reverses the order of s[j+i+1] … s[j] . | 26 | |
5F0i | [i] BLKDROP | Equivalent to DROP performed i times. | 26 | |
5Fij | [i] [j] BLKPUSH | Equivalent to PUSH s(j) performed i times.1 <= i <= 15 , 0 <= j <= 15 . | 26 | |
60 | PICK PUSHX | Pops integer i from the stack, then performs s[i] PUSH . | 18 | |
61 | ROLLX | Pops integer i from the stack, then performs 1 [i] BLKSWAP . | 18 | |
62 | -ROLLX ROLLREVX | Pops integer i from the stack, then performs [i] 1 BLKSWAP . | 18 | |
63 | BLKSWX | Pops integers i ,j from the stack, then performs [i] [j] BLKSWAP . | 18 | |
64 | REVX | Pops integers i ,j from the stack, then performs [i] [j] REVERSE . | 18 | |
65 | DROPX | Pops integer i from the stack, then performs [i] BLKDROP . | 18 | |
66 | TUCK | a b - b a b | Equivalent to SWAP OVER or to s1 s1 XCPU . | 18 |
67 | XCHGX | Pops integer i from the stack, then performs s[i] XCHG . | 18 | |
68 | DEPTH | - depth | Pushes the current depth of the stack. | 18 |
69 | CHKDEPTH | i - | Pops integer i from the stack, then checks whether there are at least i elements, generating a stack underflow exception otherwise. | 18/58 |
6A | ONLYTOPX | Pops integer i from the stack, then removes all but the top i elements. | 18 | |
6B | ONLYX | Pops integer i from the stack, then leaves only the bottom i elements. Approximately equivalent to DEPTH SWAP SUB DROPX . | 18 | |
6Cij | [i] [j] BLKDROP2 | Drops i stack elements under the top j elements.1 <= i <= 15 , 0 <= j <= 15 Equivalent to [i+j] 0 REVERSE [i] BLKDROP [j] 0 REVERSE . | 26 |