Routines |
Prev: 12171 | Up: Map | Next: 12218 |
Used by the routine at addition.
This subroutine is the first of four subroutines that are used by the main arithmetic operation routines - subtract, addition, multiply and division.
This particular subroutine prepares a floating-point number for addition, mainly by replacing the sign bit with a true numerical bit 1, and negating the number (two's complement) if it is negative. The exponent is returned in the A register and the first byte is set to 0 for a positive number and 255 for a negative number.
|
||||||||||||
PREP_ADD | 12187 | LD A,(HL) | Transfer the exponent to A. | |||||||||
12188 | LD (HL),0 | Presume a positive number. | ||||||||||
12190 | AND A | If the number is zero then the preparation is already finished. | ||||||||||
12191 | RET Z | |||||||||||
12192 | INC HL | Now point to the sign byte. | ||||||||||
12193 | BIT 7,(HL) | Set the zero flag for positive number. | ||||||||||
12195 | SET 7,(HL) | Restore the true numeric bit. | ||||||||||
12197 | DEC HL | Point to the first byte again. | ||||||||||
12198 | RET Z | Positive numbers have been prepared, but negative numbers need to be two's complemented. | ||||||||||
12199 | PUSH BC | Save any earlier exponent. | ||||||||||
12200 | LD BC,5 | There are 5 bytes to be handled. | ||||||||||
12203 | ADD HL,BC | Point one past the last byte. | ||||||||||
12204 | LD B,C | Transfer the 5 to B. | ||||||||||
12205 | LD C,A | Save the exponent in C. | ||||||||||
12206 | SCF | Set carry flag for negation. | ||||||||||
NEG_BYTE | 12207 | DEC HL | Point to each byte in turn. | |||||||||
12208 | LD A,(HL) | Get each byte. | ||||||||||
12209 | CPL | One's complement the byte. | ||||||||||
12210 | ADC A,0 | Add in carry for negation. | ||||||||||
12212 | LD (HL),A | Restore the byte. | ||||||||||
12213 | DJNZ NEG_BYTE | Loop 5 times. | ||||||||||
12215 | LD A,C | Restore the exponent to A. | ||||||||||
12216 | POP BC | Restore any earlier exponent. | ||||||||||
12217 | RET | Finished. |
Prev: 12171 | Up: Map | Next: 12218 |