Routines 
Prev: 2F8B  Up: Map  Next: 2FBA 
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 floatingpoint 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 +00 for a positive number and +FF for a negative number.


PREP_ADD  2F9B  LD A,(HL)  Transfer the exponent to A.  
2F9C  LD (HL),$00  Presume a positive number.  
2F9E  AND A  If the number is zero then the preparation is already finished.  
2F9F  RET Z  
2FA0  INC HL  Now point to the sign byte.  
2FA1  BIT 7,(HL)  Set the zero flag for positive number.  
2FA3  SET 7,(HL)  Restore the true numeric bit.  
2FA5  DEC HL  Point to the first byte again.  
2FA6  RET Z  Positive numbers have been prepared, but negative numbers need to be two's complemented.  
2FA7  PUSH BC  Save any earlier exponent.  
2FA8  LD BC,$0005  There are 5 bytes to be handled.  
2FAB  ADD HL,BC  Point one past the last byte.  
2FAC  LD B,C  Transfer the 5 to B.  
2FAD  LD C,A  Save the exponent in C.  
2FAE  SCF  Set carry flag for negation.  
NEG_BYTE  2FAF  DEC HL  Point to each byte in turn.  
2FB0  LD A,(HL)  Get each byte.  
2FB1  CPL  One's complement the byte.  
2FB2  ADC A,$00  Add in carry for negation.  
2FB4  LD (HL),A  Restore the byte.  
2FB5  DJNZ NEG_BYTE  Loop 5 times.  
2FB7  LD A,C  Restore the exponent to A.  
2FB8  POP BC  Restore any earlier exponent.  
2FB9  RET  Finished. 
Prev: 2F8B  Up: Map  Next: 2FBA 