1

I'm following along on the "Advanced Solidity" tutorial here.

I ran into an example I'm having trouble understanding. example image

In this example, why does JUMP affect the state of the stack? I expected it to only affect the program counter.

(i.e. I would expect after JUMP, at PC: 11, the length of the stack would be 3, not 2. The JUMP comes after PUSH 0x0B.)

Thanks.

Sze-Hung Daniel Tsui
  • 2,282
  • 13
  • 20

2 Answers2

3

Just to refer to the original docs. As stated in the yellow paper :

0x56 JUMP 1 0 Alter the program counter

Where 1 is the number of items taken out of the stack, 0 the number of items returned. So in your case JUMP removes '0b' from the stack and use it as the destination (PC = 11 = 0x0b).

mattes
  • 8,936
  • 5
  • 48
  • 73
1

Figured it out.

JUMP takes the value at the top of the stack to use as the destination. That value "becomes" the destination.

A JUMP could be thought of as performing a PUSH first, and moving the program counter to the pushed value.

Credit to Martin / @holiman on the ethereum/tests Gitter. Thanks.

Sze-Hung Daniel Tsui
  • 2,282
  • 13
  • 20