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.

Address
Use
0BD2
Add
ACC < DE + HL
0BC7
Subtract
ACC = DE – HL
0BF2
Multiply
ACC = DE * HL
2490
Divide
@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:

Decimal
4121
4122
4123
4124
0.5
00
00
00
80
1.0
00
00
00
81
-1.0
00
00
80
81
129.0
00
00
01
88
-129.0
00
00
81
88
257.0
00
80
00
89

—– Arithmetic Accumulator (411D-4124) —–

 
Integer
Single
Double
411D
 
 
LSB
411E
 
 
LSB
411F
 
 
LSB
4120
 
 
LSB
4121
LSB
LSB
LSB
4122
MSB
LSB
LSB
4123
 
MSB
MSB
4124
 
EXP
EXP

—– Hex Arithmetic Accululator (4127-412E) —–

 
Integer
Single
Double
4127
LSB
LSB
LSB
4128
MSB
LSB
LSB
4129
 
MSB
LSB
412A
 
EXP
LSB
412B
 
 
LSB
412C
 
 
LSB
412D
 
 
MSB
412E
 
 
EXP