5/5
_Follow along with this video:_ --- ### Understanding Stack Operations in Programming Let's look at a practical example of how the stack operates with two common opcodes `PUSH1` and `ADD`. To recap what we saw in a previous lesson, the `ADD` opcode takes the top two items on the stack and returns the sum of these items - placing this sum on the top of the stack. You may be asking **"How does data get added to the stack to begin with?"**. This is where `PUSH` comes in. By navigating to [**evm.codes**](https://www.evm.codes/?fork=shanghai) we can see that there is a different `PUSH` code, pending the byte size of the data we're adding to the stack! ### Understanding PUSH and ADD We'll start by considering how to add a 1 byte object to the stack, for this we'd use the `PUSH1` opcode.  If we were then to call the `ADD` opcode, it's going to take the top 2 items on our stack, sum them and add this sum back to the top of our stack.  > **Remember:** Were there _three_ items in our stack, the `ADD` opcode would only sum the top two items, the result would be pushed to the top of the stack, leaving the first item in our stack untouched. ### Wrap Up Here we've seen an example of two very common opcodes. - PUSH - adds items to the stack - ADD - removes the top two items from the stack, and adds their sum to the top of the stack I encourage you to familiarize yourself with more of the stack input/outputs on evm.codes. In later lessons we'll look more closely at opcodes such as MSTORE and SSTORE which remove things from the stack and write them to memory!
Follow along with this video:
Let's look at a practical example of how the stack operates with two common opcodes PUSH1 and ADD.
To recap what we saw in a previous lesson, the ADD opcode takes the top two items on the stack and returns the sum of these items - placing this sum on the top of the stack.
You may be asking "How does data get added to the stack to begin with?". This is where PUSH comes in. By navigating to evm.codes we can see that there is a different PUSH code, pending the byte size of the data we're adding to the stack!
We'll start by considering how to add a 1 byte object to the stack, for this we'd use the PUSH1 opcode.

If we were then to call the ADD opcode, it's going to take the top 2 items on our stack, sum them and add this sum back to the top of our stack.

Remember: Were there three items in our stack, the
ADDopcode would only sum the top two items, the result would be pushed to the top of the stack, leaving the first item in our stack untouched.
Here we've seen an example of two very common opcodes.
PUSH - adds items to the stack
ADD - removes the top two items from the stack, and adds their sum to the top of the stack
I encourage you to familiarize yourself with more of the stack input/outputs on evm.codes. In later lessons we'll look more closely at opcodes such as MSTORE and SSTORE which remove things from the stack and write them to memory!
A simple explanation of how PUSH and ADD opcodes work in EVM - In this lesson, we discuss the role of the stack in Ethereum Virtual Machine (EVM) execution and the PUSH and ADD opcodes. We look at how to understand and interpret stack input and output, and we see how these two opcodes function in a practical application.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Course Overview
About the course
Assembly
Writing smart contracts using Huff and Yul
Ethereum Virtual Machine OPCodes
Formal verification testing
Smart contract invariant testing
Halmos, Certora, Kontrol
Security researcher
$49,999 - $120,000 (avg. salary)
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
Guest lecturers:
Last updated on August 11, 2025
Duration: 30min
Duration: 4h 38min
Duration: 3h 57min
Duration: 1h 56min
Course Overview
About the course
Assembly
Writing smart contracts using Huff and Yul
Ethereum Virtual Machine OPCodes
Formal verification testing
Smart contract invariant testing
Halmos, Certora, Kontrol
Security researcher
$49,999 - $120,000 (avg. salary)
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
Guest lecturers:
Last updated on August 11, 2025