Solidity Tutorial : all about Assembly

Jean Cvllr
16 min readDec 25, 2019


What is Assembly?

Any program written in a high level language like C, Go, or Java is first compiled down to what is called an assembly language, before it is executed. But what is assembly?

Assembly ( also called assembler language ) refers to any low-level programming language that is converted to machine code using an assembler. Assembler languages are tied to either a physical or a virtual machine, because they implement its instruction set. An instruction tells simply the CPU to do some fundamental task, such as adding two numbers

Examples of processors are the Intel x86 or ARM. Intel x86 has around 1503 machine instructions. They are commonly referred as opcodes.

Understand the EVM and the Stack

The Ethereum Virtual Machine (EVM), has also its own instruction set. At the current date that I have written this sentence ( Brexit day + 1, so 31/01/20 ):

The EVM contains 144 opcodes in its instruction set (number based on the listing in the Geth client)

These instructions are abstracted by Solidity, its high level language for writing smart contract.

However, Solidity supports inline assembly in its code. See below:

contract Assembler {    function do_something_cpu() public {

assembly {
// start writing evm assembler language


The EVM is a stack machine. A stack is a data structure where you can only add (= PUSH) and remove (= POP) values from the top. The last item added on the stack is the first that gets removed. This is what we call a LIFO order (Last in, First out).

If you want to learn more about the fundamentals of stack