ROM Routines - Math

ROM ROUTINES (INTEGER MATH)

The following integer math routines make use ACC to contain the result of the operation. ACC is 2 locations in memory at 4121 & 4122 (LSB,MSB). The number type flag (NTF) at 40AF must also be set to 02 to indicate integer.


AddressUseFunction
0BD2AddACC = DE + HL
0BC7SubtractACC = DE - HL
0BF2MultiplyACC = DE * HL
2490Divide@BC = DE / HL

Note that on integer overflow +, -, & * return a single precision floating point number in ACC at 4121-4124 (LSB,LSB,MSB,EXPonent). Also, / always returns a single precision floating point number. In all cases you should check NTF for the type of the result (single= 4).


Integers are stored in twos compliment form. Single precision floating point numbers are stored as a normalized binary fraction, with an assumed decimal point before the most significant bit. Since the msb is always a 1, the most significant bit also doubles as the sign bit by making it a 0 for positive and 1 for negative. The binary exponent is stored in excess 128 form; that is, 128 is added to the actual binary exponent needed. The number 0 is stored as a zero mantissa and exponent. A couple of examples are shown below:

Decimal4121412241234124
0.500000080
1.000000081
-1.000008081
129.000000188
-129.000008188
257.000800089