Skip to content

Latest commit

 

History

History
113 lines (85 loc) · 2.64 KB

File metadata and controls

113 lines (85 loc) · 2.64 KB

← Back to Instruction Set: Quick Reference

MUL

Multiplication (a * b)

Opcodes 0x04-0x05 (2 wire formats)

M[dstOffset] = M[aOffset] * M[bOffset]

Details

Performs multiplication. Both operands must have the same type tag. For integer types (UINT8, UINT16, UINT32, UINT64, UINT128), the operation is performed modulo 2^k where k is the bit-width (e.g., k=8 for UINT8). For FIELD type, the operation is performed modulo p (the BN254 field prime). The result inherits the tag from the operands.

Gas Costs

Component Value Scales with
L2 Base 27 -
DA Base 0 -
L2 Addressing 3 3 L2 gas per indirect memory offset
3 L2 gas per relative memory offset

* See Gas Metering for details on how gas costs are computed and applied.

Operands

Name Type Description
aOffset Memory offset Memory offset of the first factor
bOffset Memory offset Memory offset of the second factor
dstOffset Memory offset Memory offset where the result will be written

Wire Formats

See Wire Format page for an explanation of wire format variants and opcode naming (e.g., why ADD_8 vs ADD_16).

MUL_8 (Opcode 0x04):

---
title: "MUL_8"
config:
  packet:
    bitsPerRow: 40
---
packet-beta
0-7: "Opcode (0x4)"
8-15: "Addressing modes"
16-23: "Operand: aOffset"
24-31: "Operand: bOffset"
32-39: "Operand: dstOffset"
Loading

MUL_16 (Opcode 0x05):

---
title: "MUL_16"
config:
  packet:
    bitsPerRow: 64
---
packet-beta
0-7: "Opcode (0x5)"
8-15: "Addressing modes"
16-31: "Operand: aOffset"
32-47: "Operand: bOffset"
48-63: "Operand: dstOffset"
Loading

Addressing Modes

See Addressing page for a detailed explanation.

8-bit bitmask: 2 bits per memory offset operand (indirect flag + relative flag)

Memory offset operands (aOffset, bOffset, dstOffset) are encoded as follows:

---
title: "Addressing Mode Bitmask"
config:
  packet:
    bitWidth: 128
    bitsPerRow: 8
---
packet-beta
  0: "aOffset is indirect"
  1: "aOffset is relative"
  2: "bOffset is indirect"
  3: "bOffset is relative"
  4: "dstOffset is indirect"
  5: "dstOffset is relative"
  6: "Unused"
  7: "Unused"
Loading

Tag Checks

  • T[aOffset] == T[bOffset]

Tag Updates

  • T[dstOffset] = T[aOffset]

Error Conditions

  • TAG_MISMATCH: Operands have different type tags
  • MEMORY_ACCESS_OUT_OF_RANGE: Memory offset operand exceeds addressable memory

← Back to Instruction Set: Quick Reference