Skip to main content

FAIL

Report that an unexpected problem has occurred.

OpcodeBytesCyclesFormExample
$1011FAIL IF OVERFLOWFAIL IF OVERFLOW
$1111FAIL IF CARRYFAIL IF CARRY
$2022FAIL IF NULL I:_FAIL IF NULL I:4
$2121FAIL {U_BYTE}FAIL 123
$B041FAIL {U_TRIO}FAIL $12_3ABC
$2222FAIL I:_FAIL I:4

Notes

  • The FAIL instruction 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 OVERFLOW fails only if the overflow flag (OF) is 1.

  • FAIL IF CARRY fails only if the carry flag (CF) is 1.

  • FAIL IF NULL fails 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 codeMeaning
0 – 15Reserved by the Chombit hardware.
0Invalid 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.
4Null address fault: The address bus tried to dereference a null pointer.

Example: CHOMBIT CPU FAULT: ACCESSED A NULL MEMORY ADDRESS
5Read-only fault: The address bus tried to write to read-only memory.

Example: CHOMBIT CPU FAULT: CANNOT WRITE TO READ-ONLY ADDRESS $XXXX_XXXX
6Invalid 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
7Stack 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 – 31Reserved 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 – 255Custom codes available for the user's program.
≥256Values larger than 255 will be interpreted as a memory address containing a custom text string to display.

See also