2

In the tutorial here, the program counter increases by 2 for a PUSH1 opcode. Then it increases by 1 for other opcodes. Why is this? Does it have to do with the opcodes size in memory? Aren't they all 256 bit?

PC: 11 STACK: [32] MEM: [], STORAGE: {}

PC: 13 STACK: [2020202020] MEM: [], STORAGE: {}

PC: 14 STACK: [2020202020, 0] MEM: [], STORAGE: {}

PC: 16 STACK: [2020202020, 54] MEM: [], STORAGE: {}

PC: 17 STACK: [] MEM: [], STORAGE: {54: 2020202020}
  • FYI refer here to learn how to write a URL markdown – Achala Dissanayake Aug 29 '17 at 13:56
  • Hi, can you accept the answer if it helped? or need more clarification? – Achala Dissanayake Jan 15 at 6:51
2

As shown in the example code there

PUSH1 0 CALLDATALOAD SLOAD NOT PUSH1 9 JUMPI STOP JUMPDEST PUSH1 32 CALLDATALOAD PUSH1 0 CALLDATALOAD SSTORE

the indexing is arranged as;

0 -> PUSH1

1 -> 0

2 -> CALLDATALOAD

3 -> SLOAD ......

In the program 0, it refers to PUSH1 and pushes the value at 1 to stack and the next instruction at the 2 should be executed. Hence the PC becomes 2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.