FAIL
Report that an unexpected problem has occurred.
| Opcode | Bytes | Cycles | Form | Example |
|---|---|---|---|---|
| $10 | 1 | 1 + 5 | fail if overflow | fail if overflow |
| $11 | 1 | 1 + 5 | fail if carry | fail if carry |
| $20 | 2 | 2 + 5 | fail if null i:_ | fail if null i:4 |
| $21 | 2 | 1 + 5 | fail {u_byte} | fail 123 |
| $b0 | 4 | 1 + 5 | fail {u_trio} | fail $12_3abc |
| $22 | 2 | 2 + 5 | fail i:_ | fail i:4 |
Notes
-
The
failinstruction typically will display an error message and terminate the program with a fail cat. However, its behavior is customizable. -
This instruction implements the Hybrix language's kernel::fail() function.
-
This instruction invokes a CPU event handler, which adds 5 clock cycles, plus whatever time is spent handling the event.
-
fail if overflowfails only if the overflow flag (OF) is1. -
fail if carryfails only if the carry flag (CF) is1. -
fail if nullfails only if the specified register contains a zero value. -
The other forms fail unconditionally. Their operand specifies a failure code number. If the number is greater than 255, the debugger will interpret it as a memory address, and expect to find a string message there. Otherwise, the number is printed.
| Failure code | Meaning |
|---|---|
| 0 – 15 | Reserved by the Chombit hardware. |
| 0 | Invalid instruction fault: The IP points to an invalid opcode.Example: Chombit CPU fault: Invalid instruction at $xxxx_xxxx |
| 1 | "Numeric overflow; the result does not fit in the register" Reported by fail if overflow. |
| 2 | "Unsigned overflow; the result does not fit in the register" Reported by fail if carry. |
| 3 | "Accessed a null pointer" Reported by fail if null. |
| 4 | Null address fault: The address bus tried to dereference a null pointer.Example: Chombit CPU fault: Accessed a null memory address |
| 5 | Read-only fault: The address bus tried to write to read-only memory.Example: Chombit CPU fault: Cannot write to read-only address $xxxx_xxxx |
| 6 | Invalid address fault: The address bus tried to access a memory address that does not exist.Example: Chombit CPU fault: Accessed an invalid memory address $xxxx_xxxx |
| 7 | Stack fault: The sp register became larger than the gp register. This detection is performed only if io::stack_guard is 1, and only for push, gpush, and add sp instructions.Example: Chombit CPU fault: Stack overflow |
| 16 – 31 | Reserved for usage by the Hybrix compiler and framework. |
| 16 | "The main::start() function has returned" |
| 17 | "Array index out of bounds" |
| 18 | "array::resize() failed because the array is not large enough" |
| 19 | "array::copy_from() failed because the target array is not large enough" |
| 20 | "There is not enough memory to create this object" |
| 32 – 255 | Custom codes available for the user's program. |
| ≥256 | Values larger than 255 will be interpreted as a memory address containing a custom text string to display. |
See also
- CPU events:
failtriggers a failure CPU event