FAIL
Report that an unexpected problem has occurred.
| Opcode | Bytes | Cycles | Form | Example |
|---|---|---|---|---|
| $10 | 1 | 1 | FAIL IF OVERFLOW | FAIL IF OVERFLOW |
| $11 | 1 | 1 | FAIL IF CARRY | FAIL IF CARRY |
| $20 | 2 | 2 | FAIL IF NULL I:_ | FAIL IF NULL I:4 |
| $21 | 2 | 1 | FAIL {U_BYTE} | FAIL 123 |
| $B0 | 4 | 1 | FAIL {U_TRIO} | FAIL $12_3ABC |
| $22 | 2 | 2 | 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