| Routines

2FDD: THE 'SHIFT ADDEND' SUBROUTINE

Used by the routines at PRINT_FP and addition. This subroutine shifts a floating-point number up to 32 places right to line it up properly for addition. The number with the smaller exponent has been put in the addend position before this subroutine is called. Any overflow to the right, into the carry, is added back into the number. If the exponent difference is greater than 32, or the carry ripples right back to the beginning of the number then the number is set to zero so that the addition will not alter the other number (the augend).
Input
A | Number of shifts to perform
D'E'DE | Mantissa of number to shift right
L' | Sign byte of number to shift right (+00 or +FF)
SHIFT_FP | 2FDD | AND A | If the exponent difference is zero, the subroutine returns at once.
| 2FDE | RET Z
| 2FDF | CP $21 | If the difference is greater than +20, jump forward.
| 2FE1 | JR NC,ADDEND_0
| 2FE3 | PUSH BC | Save BC briefly.
| 2FE4 | LD B,A | Transfer the exponent difference to B to count the shifts right.
ONE_SHIFT | 2FE5 | EXX | Arithmetic shift right for L', preserving the sign marker bits.
| 2FE6 | SRA L
| 2FE8 | RR D | Rotate right with carry D', E', D and E, thereby shifting the whole five bytes of the number to the right as many times as B counts.
| 2FEA | RR E
| 2FEC | EXX
| 2FED | RR D
| 2FEF | RR E
| 2FF1 | DJNZ ONE_SHIFT | Loop back until B reaches zero.
| 2FF3 | POP BC | Restore the original BC.
| 2FF4 | RET NC | Done if no carry to retrieve.
| 2FF5 | CALL ADD_BACK | Retrieve carry.
| 2FF8 | RET NZ | Return unless the carry rippled right back. (In this case there is nothing to add.)
ADDEND_0 | 2FF9 | EXX | Fetch L', D' and E'.
| 2FFA | XOR A | Clear the A register.
This entry point is used by the routine at multiply.
ZEROS_4_5 | 2FFB | LD L,$00 | Set the addend to zero in D', E', D and E, together with its marker byte (sign indicator) L', which was +00 for a positive number and +FF for a negative number. This produces only 4 zero bytes when called for near underflow by multiply.
| 2FFD | LD D,A
| 2FFE | LD E,L
| 2FFF | EXX
| 3000 | LD DE,$0000
| 3003 | RET | Finished.