×   Main Menu ALL The 8BS News Manuals (New menu) Links Worth a Look Tools Disc and Basic Webring Site Map 8BS Guestbook Old Guest Book Me The Barnsley Rovers   
8-Bit Software

The BBC and Master Computer Public Domain Library

Normalise FWA#2 [only bit-by-bit method]

Submitted by Steve Fewell

Routine: anorm[2]
Name: Normalise Floating-Point Accumulator (FWA)#2 [only bit-by-bit method]
Starting Address: &81E2
Entry criteria: The FWA contains a floating-point number. Y = Exponent (?&30). A = MSB of FWA's Mantissa (?&31).
Exit: FWA has been normalised

Description:
'OR' the Accumulator with 0 to set the status flags according to the value.

If A = Negative then the top bit is set and the FWA is already normalised, so store A & Y back into &31 and &30 (respectively) and exit.

If A is zero then the number in the FWA is considered to be zero, so the FWA's sign, Exponent and Mantissa byte 1 are set to zero to indicate this, and the routine is exited. This uniquely identifies the number zero.

Otherwise, the top bit of the Mantissa is not 1, so we need to normalise the FWA as follows:
            ==> Keep on decrementing the exponent (Y) and multiplying the mantissa by 2 (moving its bits left a position), until the top bit is set (A becomes negative).

When the number is normalised, store A & Y back into &31 and &30 (respectively) and exit.

Disassembly for the Normalise FWA#2 [only bit-by-bit method] routine

81E2   009 000 09 00 ORA#&00
81E4 0 048 012 30 0C BMI 12 --> &81F2
81E6   240 228 F0 E4 BEQ -28 --> &81CC
81E8   136 88 DEY
81E9 4 006 052 06 34 ASL &34
81EB &3 038 051 26 33 ROL &33
81ED &2 038 050 26 32 ROL &32
81EF * 042 2A ROL A
81F0   016 246 10 F6 BPL -10 --> &81E8
81F2 1 133 049 85 31 STA &31
81F4 0 132 048 84 30 STY &30
81F6 ` 096 60 RTS

Complete Zero Number:

81CC d. 100 046 64 2E STZ &2E
81CE d0 100 048 64 30 STZ &30
81D0 d/ 100 047 64 2F STZ &2F
81D2 d1 100 049 64 31 STZ &31
81D4 ` 096 60 RTS

 


 Back to 8BS
Or