Skip to main content

FAIL

Report that an unexpected problem has occurred.

OpcodeBytesCyclesFormExample
$1011 + 5fail if overflowfail if overflow
$1111 + 5fail if carryfail if carry
$2022 + 5fail if null i:_fail if null i:4
$2121 + 5fail {u_byte}fail 123
$b041 + 5fail {u_trio}fail $12_3abc
$2222 + 5fail 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