FA-89853 / Bytecode virtual machines / Member archive
Relative-jump VM: SUB subtracts second-from-top from top · case 03
Decrementing counters increase and swapped operands produce negated differences.
Case contract
Flat int bytecode, byte addressed: 0 HALT, 1 PUSH imm, 2 ADD, 3 SUB (second-from-top minus top), 4 JMP rel, 5 JZ rel (pops condition, branches when it is 0), 6 DUP, 7 SWAP, 8 PRINT (pop to out). Relative displacements are measured from the address after the one-byte operand. Every executed instruction including HALT costs one unit of fuel; with fuel exhausted report status fuel. Return status, pc, printed values and stack; stack underflow, bad pc and bad opcode are statuses.
Why this case matters
Branch displacement bases, operand order and fuel accounting are classic interpreter-loop defects.
One recorded failure
Sample boundary fixtureThis sample comes from the broken implementation of a controlled reproducer.
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression: countdown loop prints n..1 | {"out": [4, -3, 4, -3, 4, -3, 4, -3, 4, -3, 4, -3, 4, -3, 4, -3, 4, -3, 4, -3, 4, -3, 4, -3, 4, -3, 4, -3], "pc": 6, "stack": [4, 4], "status": "fuel"} | {"out": [4, 3, 2, 1], "pc": 12, "stack": [0], "status": "halt"} | Failed |
MEMBER ARCHIVE
The complete case is available to members.
This record includes three runnable implementations, regression fixtures, execution results, and source hashes.
Member access is invitation-based. Sign in with your invited account to inspect the sources.
Sign in to the archive ↗