Submitted by Steve Fewell
Routine: anorm[1]
Name: Normalise Floating-Point number in the FWA [bit-by-bit and
byte-by-byte methods supported]
Starting Address: &81F7
Entry criteria: The FWA contains a
floating-point number.
Exit: FWA has been normalised (The top bit
of the FWA is set, and the exponent adjusted accordingly)
Description:
Unlike the Normalise FWA#2 routine, this
routine does not have any special entry requirements (i.e. certain bytes of the
number needing to be copied to the A and Y registers).
If ?&31 is negative (the FWA Mantissa's top bit is already set) then exit as the number is already normalised.
If FWA's Mantissa byte 1 (?&31) is zero then OR ?&31 with ?&32, ?&33, ?&34 and ?&35. If the result is zero, then the whole Mantissa (and hence, the whole number) is zero, so jump to &81CC to zero the FWA's Exponent, Exponent Overflow and Sign bytes, and exit.
[Byte-by-Byte method - Normalise one byte at a time]
If FWA's Mantissa byte 1 (?&31) is zero, but the FWA doesn't not contain
zero, then Load A with the FWA's Exponent (?&30), and [&8209]
move the FWA Mantissa byte 2 to the FWA Mantissa Byte 1, move the FWA Mantissa
byte 3 to the FWA Mantissa Byte 2, move the FWA Mantissa byte 4 to the FWA
Mantissa Byte 3 and move the FWA Mantissa rounding byte to the FWA Mantissa Byte
4. Set the FWA Mantissa Rounding byte to zero. Subtract 8 from the exponent (as
we have moved the number along 8 bits), and decrement the FWA Exponent Overflow
(if the Exponent underflowed). If FWA Mantissa Byte 1 is still zero, then we
need to normalise by another 8 bits, so jump back to &8209 to move the
Mantissa along another byte.
If by moving the Mantissa along byte-by-byte, we now have a normalised number,
store A back in the FWA Exponent byte and exit, otherwise jump to &822C to
proceed with the bit-by-bit method.
[Bit-by-Bit method - Normalise one bit at a time]
If FWA's Mantissa byte 1 (?&31) is not zero, but the FWA isn't
normalised, then Load A with the FWA's Exponent (?&30), and [&822C]
subtract 1 from the FWA Exponent byte [A], and decrement the FWA Exponent
Overflow byte if the result underflowed, and shift the FWA Mantissa left one bit
(multiply by 2) so that the bits move from the ?&35 end of the number to the
?&31 end of it. Keep repeating this until the top bit is set.
Now that the number is normalised, store A back in the FWA Exponent Byte (?&30), and exit.
Disassembly for the Normalise FWA#2 routine
81F7 | 1 | 165 049 | A5 31 | LDA &31 |
81F9 | 0 | 048 217 | 30 D9 | BMI -39 --> &81D4 [RTS] |
81FB | - | 208 045 | D0 2D | BNE 45 --> &822A |
81FD | 2 | 005 050 | 05 32 | ORA &32 |
81FF | 3 | 005 051 | 05 33 | ORA &33 |
8201 | 4 | 005 052 | 05 34 | ORA &34 |
8203 | 5 | 005 053 | 05 35 | ORA &35 |
8205 | 240 197 | F0 C5 | BEQ -59 --> &81CC | |
8207 | 0 | 165 048 | A5 30 | LDA &30 |
8209 | 2 | 164 050 | A4 32 | LDY &32 |
820B | 1 | 132 049 | 84 31 | STY &31 |
820D | 3 | 164 051 | A4 33 | LDY &33 |
820F | 2 | 132 050 | 84 32 | STY &32 |
8211 | 4 | 164 052 | A4 34 | LDY &34 |
8213 | 3 | 132 051 | 84 33 | STY &33 |
8215 | 5 | 164 053 | A4 35 | LDY &35 |
8217 | 4 | 132 052 | 84 34 | STY &34 |
8219 | d5 | 100 053 | 64 35 | STZ &35 |
821B | 8 | 056 | 38 | SEC |
821C | 233 008 | E9 08 | SBC#&08 | |
821E | 176 002 | B0 02 | BCS 2 --> &8222 | |
8220 | / | 198 047 | C6 2F | DEC &2F |
8222 | 1 | 164 049 | A4 31 | LDY &31 |
8224 | 240 227 | F0 E3 | BEQ -29 --> &8209 | |
8226 | 0 | 048 023 | 30 17 | BMI 23 --> &823F |
8228 | 128 002 | 80 02 | BRA 2 --> &822C | |
822A | 0 | 165 048 | A5 30 | LDA &30 |
822C | 024 | 18 | CLC | |
822D | 233 000 | E9 00 | SBC#&00 | |
822F | 176 002 | B0 02 | BCS 2 --> &8233 | |
8231 | / | 198 047 | C6 2F | DEC &2F |
8233 | 5 | 006 053 | 06 35 | ASL &35 |
8235 | &4 | 038 052 | 26 34 | ROL &34 |
8237 | &3 | 038 051 | 26 33 | ROL &33 |
8239 | &2 | 038 050 | 26 32 | ROL &32 |
823B | &1 | 038 049 | 26 31 | ROL &31 |
823D | 016 238 | 10 EE | BPL -18 --> &822D | |
823F | 0 | 133 048 | 85 30 | STA &30 |
8241 | ` | 096 | 60 | RTS |