pc
is the program counter, which points to the current Cairo instructionap
is the allocation pointer, which points to the current available memory addressfp
is the frame pointer, which points to the current frame in the “call stack”Figure 1: Cairo instruction (little-endian)
dst
, op0
, and op1
.
The next 15 bits are flags. The dst_reg
and op0_reg
1-bit flags indicate whether to use the ap
or the fp
register as the base for the dst
and op0
operands. The op1_src
flag supports a wider range of base values for the op1
operand: op0
, pc
, fp
, and ap
. The res_logic
flag indicates how to compute the res
operand: op1
, op0 + op1
, or op0 * op1
. The pc_update
and ap_update
flags show how to update the pc
and ap
registers after computing the operands. The opcode
flag indicates whether this instruction belongs to a predefined opcode (e.g., CALL
, RET
, ASSERT_EQ
) and also defines how the ap
and fp
registers should be updated.
ADD
, MUL
, JUMP
, CALL
), and the current version of Cairo also defines a new set of opcodes used to improve the performance of heavy computations such as Blake2s hashing and QM31 addition and multiplication.
Since the 64-bit instruction structure is not flexible enough to support this extended set of opcodes, Cairo extends the instruction size to 72 bits and uses the last 9 bits as the opcode extension value.
Figure 2: New instruction format with opcode extension
0
: Stone (original opcodes)1
: Blake2
: BlakeFinalize3
: QM31Operation