Skip to main content

Try it Live

Run Opcode examples in the interactive playground

Opcode.format()

Format single instruction as human-readable assembly string.

Parameters

  • instruction: Instruction - Parsed instruction to format

Returns

string - Formatted instruction string Format: "<offset>: <mnemonic> [immediate]"

Output Format

  • Offset: 4-digit hex with leading zeros (e.g., 0000, 002A, 00FF)
  • Mnemonic: Uppercase opcode name (e.g., PUSH1, ADD, SSTORE)
  • Immediate: Lowercase hex with 0x prefix for PUSH operations

Examples

Format Different Opcodes

Custom Formatting

Colorized Output

Format with Stack Effect

Batch Format

Use Cases

Debug Output

Build Control Flow Graph

Performance

  • O(1) time complexity
  • String allocation for output
  • Hex conversion for offset and immediate data
  • Very fast - just string formatting