×   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

A541 Unpack Floating-Point Variable to FWA

Submitted by Steve Fewell

Routine:aunp
Name: Unpack Floating-Point Variable to FWA
Starting Address: &A541 (or &A539 to set argp to &046C first)
Entry criteria: &4A and &4B (the argp) point to a 5-byte Floating-Point variable to unpack.
Exit: The FWA contains the value of the variable.

Description:

If called from &A539 then set argp to point to variable location &046C first.
The FWA value will be extracted from the packed floating-point value at the address pointed to by argp.

Set FWA Rounding byte = 0.
Set FWA Overflow byte = 0.
FWA Mantissa 4 = 5th byte of the packed variable
FWA Mantissa 3 = 4th byte of the packed variable
FWA Mantissa 2 = 3rd byte of the packed variable
FWA Mantissa Sign = 2nd byte of the packed variable
FWA Exponent = 1st byte of the packed variable

If the Exponent is zero, then check whether the Mantissa byte 2, Mantissa byte 3
and Mantissa byte 4 are also zero. If so, then the FWA value = 0.0 so store zero in
FWA Mantissa 1 and exit.
Mantissa 1 is formed by ORing the 2nd byte of the packed variable with #&80 to ensure that
the top bit is set - as the top bit is replaced by the sign bit in the packed form.


Disassembly for the Unpack FP Variable to FWA routine

A539 l 169 108 A9 6C LDA#&6C
A53B J 133 074 85 4A STA &4A
A53D   169 004 A9 04 LDA#&04
A53F K 133 075 85 4B STA &4B
A541 d5 100 053 64 35 STZ &35
A543 d/ 100 047 64 2F STZ &2F
A545   160 004 A0 04 LDY#&04
A547 J 177 074 B1 4A LDA (&4A),Y
A549 4 133 052 85 34 STA &34
A54B   136 88 DEY
A54C J 177 074 B1 4A LDA (&4A),Y
A54E 3 133 051 85 33 STA &33
A550   136 88 DEY
A551 J 177 074 B1 4A LDA (&4A),Y
A553 2 133 050 85 32 STA &32
A555   136 88 DEY
A556 J 177 074 B1 4A LDA (&4A),Y
A558 . 133 046 85 2E STA &2E
A55A   168 A8 TAY
A55B J 178 074 B2 4A LDA (&4A)
A55D 0 133 048 85 30 STA &30
A55F   208 009 D0 09 BNE 9 --> &A56A
A561   152 98 TYA
A562 2 005 050 05 32 ORA &32
A564 3 005 051 05 33 ORA &33
A566 4 005 052 05 34 ORA &34
A568   240 003 F0 03 BEQ 3 --> &A56D
A56A   152 98 TYA
A56B   009 128 09 80 ORA#&80
A56D 1 133 049 85 31 STA &31
A56F ` 096 60 RTS

 


 Back to 8BS
Or