Skip to content

Latest commit

 

History

History
28 lines (18 loc) · 1.59 KB

57.mdx

File metadata and controls

28 lines (18 loc) · 1.59 KB
fork group
Frontier
Stack Memory Storage and Flow Operations

Index 1 is top of the stack. See PUSH.

Notes

The program counter (PC) is a byte offset in the deployed code. It indicates which instruction will be executed next. When an ADD is executed, for example, the PC is incremented by 1, since the instruction is 1 byte. The PUSH instructions are bigger than one byte, and so will increment the counter accordingly.

The JUMPI instruction may alter the program counter, thus breaking the linear path of the execution to another point in the deployed code. It is used to implement functionalities like loops and conditions.

Stack input

  1. counter: byte offset in the deployed code where execution will continue from. Must be a JUMPDEST instruction.
  2. b: the program counter will be altered with the new value only if this value is different from 0. Otherwise, the program counter is simply incremented and the next instruction will be executed.

Example

See in playground.

Error cases

The state changes done by the current context are reverted in those cases:

  • Not enough gas.
  • Not enough values on the stack.
  • Counter offset is not a JUMPDEST. The error is generated only if the JUMP would have been done.