Supported Opcodes
| Opcode | Hex | Stack Input | Stack Output | Description |
|---|---|---|---|---|
| LT | 0x10 | a, b | a < b | Less than comparison |
| GT | 0x11 | a, b | a > b | Greater than comparison |
| EQ | 0x14 | a, b | a == b | Equality comparison |
| ISZERO | 0x15 | a | a == 0 | Check if value is zero |
LT (0x10)
Compares if the second stack value is less than the first. Example:GT (0x11)
Compares if the second stack value is greater than the first. Example:EQ (0x14)
Compares if two values are equal. Example:ISZERO (0x15)
Checks if a value is zero. This is a unary operation that only consumes one stack item. Example:Implementation
Comparison operations are implemented insrc/vm.rs:188-214. They:
- Pop one or two values from the stack
- Perform the comparison using Rust’s comparison operators
- Push 1 (true) or 0 (false) onto the stack
Return Values
All comparison opcodes return:
0x01(or just1) for true0x00(or just0) for false
Common Patterns
Comparison opcodes are often used for:- Conditional logic: Check conditions before executing code paths
- Input validation: Verify values meet requirements
- Loop counters: Compare iteration counters with limits