Added check for most-negative-number in `abs` subroutine.
@ abs(signed number) <-- TOS
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
NSSVTSSSTN | Mark: 10001 (absolute value)
+
+@ Catch -(2^63) as a special case since its absolute value will overflow
+@ a twos-complement 64-bit word. Return zero as though the absolute value
+@ overflowed to the bottom of the non-negative integers rather than
+@ overflowing back to the most negative integer.
+SNS | DUP
+SSTTSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSN | -(2^63)
+TSST | SUBTRACT
+NTSSSSTSSSTSSSSSSTSN | BRZ > 00010001 00000010
+
+@ Handle all the other numbers.
SNS | DUP
NTTSSSTSSSTSSSSSSSSN | BMI > 00010001 00000000
NSNSSSTSSSTSSSSSSSTN | JMP > 00010001 00000001
NSSVSSSTSSSTSSSSSSSTN | Mark: 00010001 00000001
NTN | RTS
+@ Special case: Push 0 and return.
+NSSVSSSTSSSTSSSSSSTSN | Mark: 00010001 00000010
+SNN | DROP
+SSSSN | PUSH 0
+NTN | RTS
+
#endif
--- /dev/null
+@ +1 should remain +1
+SSSTN | PUSH +1
+NSTTSSSTN | JSR > 10001 (abs)
+NSTTSSTN | JSR > 1001 (print number from stack)
+
+@ -1 should become +1
+SSTTN | PUSH -1
+NSTTSSSTN | JSR > 10001 (abs)
+NSTTSSTN | JSR > 1001 (print number from stack)
+
+@ 0 should remain 0
+SSSSN | PUSH 0
+NSTTSSSTN | JSR > 10001 (abs)
+NSTTSSTN | JSR > 1001 (print number from stack)
+
+@ Test the most negative number.
+@ It is impossible to return the true absolute value but should return zero.
+SSSTN | PUSH +1
+SSSTTTTTTN | PUSH +63
+NSTTSTTSTN | JSR > 101101 (lshift)
+NSTTSSSTN | JSR > 10001 (abs)
+NSTTSSTN | JSR > 1001 (print number from stack)
+NNN | DIE
+
+#include <logic.pvvs>
+#include <stdio.pvvs>
--- /dev/null
+@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+@
+@ This test intentionally blank.
+@
+@ If there comes a day when the tests are extended beyond testing basic
+@ functionality, include random in the new tests.
+@
+@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+
+NNN | Die
['3005_or', '', '+0+1+1-1-1'],
['3006_xor', '', '+0+1+0-2-1'],
['4001_strlen', '', '+11'],
+ ['5001_abs', '', '+1+1+0+0'],
+ ['5002_random', '', ''],
]
for test in tests: