Underflow
XJEase does not support negative integers. If you decrement an integer beyond zero it will underflow and wrap around to the maximum value represented by the variable's current width.
INT x WIDTH 5 := 0; x := x - 1; PRINT("x: 0b", BIN(x), "\n");
will give the following output:
x: 0b11111
Be careful, however, with allowing intermediate values in expressions to be negative: once a variable has underflowed, it can not overflow back to zero again. In the following code, both expressions are evaluated from left to right. In the second case, the subtraction is evaluated first and causes an underflow, resulting in an unexpected value for the whole expression.
INT normal; INT underflow; normal := 1 + 5 - 2; underflow := 1 - 2 + 5; PRINT("normal: ", normal, "\n"); PRINT("underflow: ", underflow, "\n");
normal: 4 underflow: 8
The width of the result of the subtraction is 2, since that is the width of the constant 3. The underflowed result is 0b11 (or 3). We then add 5 to that giving the unexpected result of 8.
XJTAG v4.2.5
