Skip to main content
Fift is a stack-based programming language with TON-specific features that can work with cells. TVM assembly is another stack-based language designed for TON that also handles cells. What is the difference between them?

Key differences

Fift is an interpreted language. With respect to TVM, its execution happens at compile-time — when the compiler builds the smart contract code as a BoC. That compiled code contains TVM assembly for execution at run-time on the TVM itself. Fift can appear in different forms:
  • Built-in words, constants, and variables:
  • TVM instruction bitcode definitions, like in Asm.fif:
  • Intertwined macros and TVM opcodes, like in wallet_v3_r2.fif:
The last code fragment resembles TVM assembly because most of it actually is TVM assembly — the only difference is that none of the TVM instructions will be executed immediately. Instead, their opcodes will be embedded into the resulting smart contract BoC for further TVM execution. Where Fift works at compile-time to shape the contract’s code, TVM assembly runs that code on the actual blockchain.

Smart contract usage

(Fift) Including large BoCs in contracts

Include large BoCs with toncli by:
  1. Editing project.yaml to include fift/blob.fif:
  2. Adding the BoC to fift/blob.boc
  3. Including this code in fift/blob.fif:
Access the blob in the contract:

(TVM assembly) Converting integers to strings

Fift primitives cannot convert integers to strings at runtime because Fift operates at compile-time. For runtime conversion, use TVM assembly like in this solution from the 3rd TON Smart Challenge:

(TVM assembly) Efficient modulo multiplication

Compare these implementations:
The x{A988} opcode implements an optimized division operation with built-in multiplication. This specialized instruction directly computes just the modulo remainder of the operation, skipping unnecessary computation steps. The s, suffix then handles the result storage - it takes the resulting slice from the stack’s top and efficiently writes it into the target builder. Together, this combination delivers substantial gas savings compared to conventional approaches.