# Operation Codes (Opcodes)

In the previous section, we went over the data structures that define the state of the EVM at any point of time. While we might have a grasp at their implementation, what we haven't yet covered is how we can manipulate these data structures.&#x20;

In this section, we will go over opcodes - the set of all instructions supported by the EVM which allows us to manipulate the data structures previously mentioned. The number of opcodes available to use is large; therefore, we will go over opcodes by identifying the different grouping of opcodes available to us. In particular, we will go over opcodes in the following order:

* Opcodes related solely to the stack
* Opcode related to memory
* Opcodes related to storage
* Arithmetic Opcodes
* Logical & Bitwise Opcodes
* Message Opcodes
* Environment Opcodes
* Event Opcodes
* Contract Creation, Return, and Miscellaneous Opcodes

### Stack-Based Opcodes

As it will become evident throughout the rest of this section, the stack is the main data structure for which we will extract the arguments for other opcodes. This brings up a good first question - how do we actually get items onto the stack? We will look at our first opcode for this - the PUSH1 opcode. The PUSH1 opcode has the following syntax (in hexadecimal notation):

```
60 <arg>
```

where `arg` is the value to push onto the stack. The next logical question to ask is what value can I set `arg` to? To this, look at the integer attached to `PUSH1`. The `1` indicates that `arg` is at most a 1-byte value. Therefore, the `PUSH1` opcode allows us to push a 1-byte value onto the stack.&#x20;

If you recall from the [EVM Data Structures](/understanding-the-evm/the-ethereum-virtual-machine/evm-data-structures.md) section, each element on the stack is 32-byte long. Therefore, we are not limited to just pushing 1-byte values onto the stack. In fact, for any `1 <= n <= 32`, there exists a `PUSHn` opcode.&#x20;

While pushing values onto the stack allows us to feed in arguments to the EVM, consider the following scenarios:

* What if we want to switch the position of an element on the stack?
* What if we wanted to duplicate elements on the stack?

To address both of these scenarios, we have the `SWAP` and the `DUP` opcodes which, as their abbreviations might suggest, allow us to swap and duplicate stack items, respectively.

### Memory-Based Opcodes

### Storage-Based Opcodes


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://cs4998.cornellblockchain.org/understanding-the-evm/the-ethereum-virtual-machine/operation-codes-opcodes.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
