Skip to main content

TVM Instructions

caution

Due to limitations in Docusaurus, the single-page version moved here.

...

Introduction

This document provides a list of TVM instructions along with their opcodes and mnemonics.

info

TVM.pdf concept document for TON Virtual Machine (may include outdated information).

Fift is a stack-based programming language designed to manage TON smart contracts. The Fift assembler is a Fift library that converts mnemonics of TVM instructions into their binary representation.

A description of Fift, including an introduction to the Fift assembler, can be found here.

This document specifies the corresponding mnemonic for each instruction.

Note the following:

  1. Fift is a stack-based language, therefore all the arguments of any instruction are written before it (e.g. 5 PUSHINT, s0 s4 XCHG).
  2. Stack registers are denoted by s0, s1, ..., s15. Other stack registers (up to 255) are denoted by i s() (e.g. 100 s()).
  3. Control registers are denoted by c0, c1, ..., c15.

Gas prices

The gas price of each instruction is specified in this document. The basic gas price of an instruction is 10 + b, where b is the instruction length in bits. Some operations have additional fees:

  1. Parsing cells: Transforming a cell into a slice costs 100 gas units if the cell is loading for the first time and 25 for subsequent loads during the same transaction. For such instructions, two gas prices are specified (e.g. CTOS: 118/43).
  2. Cell creation: 500 gas units.
  3. Throwing exceptions: 50 gas units. In this document the exception fee is only specified for an instruction if its primary purpose is to throw (e.g. THROWIF, FITS). If the instruction only throws in some cases, two gas prices are specified (e.g. FITS: 26/76).
  4. Tuple creation: 1 gas unit for every tuple element.
  5. Implicit jumps: 10 gas units for an implicit jump, 5 gas units for an implicit back jump. This fee is not a part of any instruction.
  6. Moving stack elements between continuations: 1 gas unit per element, however moving the first 32 elements is free.
info

A full machine-readable list of TVM instructions is available here.

Each section of TVM Instructions includes a built-in search component for finding opcodes specific to that section as well.

On this page, however, the search covers all existing opcodes, providing a comprehensive search option across the entire opcode range.

Feel free to use the search field below to find a specific instruction:

OpcodeFift syntaxStackDescriptionGas
Please enter a search query
No results found

TVM Instructions Content List

...

See Also