×   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

A027 '^' Operator (raise FWA to the Power)

Submitted by Steve Fewell

Description:

Convert value to a Float if it is an Integer. If it is a String, then Type mismatch error.
Push FWA to the Stack.
Obtain second value, convert to Float if it is an Integer. If it is a String, then Type
mismatch error.
If the FWA exponent of the Power value is less than #&87 then do the following:
 *   Call &82E0 to Split the FWA into an Integer value (&49) and a Fractional
     value (FWA).
 *   If the Fractional Part of the FWA is 0.00 then Pop the Float back from Stack to the FWA;
     call &A5BE to raise the FWA to the power of the Integer in &49; and
     return to level 6 of the expression handler with FWA = the result.
 *   Otherwise, store the fractional power value in the Temporary Floating-Point variable at &0476.
 *   Unpack the Float value from the Stack (without popping it, as we will pop it later) into the FWA.
 *   Raise the FWA to the Integer Part of the Power value (&49).

Otherwise, If the FWA exponent of the Power value is >= #&87 then do the following:
 *   Store the Power value (in the FWA) in the Temporary Floating-Point variable at &0476.
 *   Set the FWA = 1.0.

Now we have the power value in &0476 and the FWA set to any result calculated so far.
Next, store the result calculated so far (in the FWA) to Temporary Floating-Point variable at &0471.
Pop the Float from the Stack (the first value - that is the value to raise to the power) to the FWA.
Call LN routine to get the natural logorithm of the Float value.
Multiply the natural logorithm result with the Float Power value (&0476).
Call EXP routine to obtain the exponental of this result.
This gives us the first value raised to the power of the Float Power value.

Next, we need to multiply this result by any result we have already calculated (in &0471),
as the Integer part of the power may have already been calculated separately.
Lastly, exit with A = #&FF (as we have a Floating-Point result).


Disassembly for the '^' Operator routine

A027   168 A8 TAY
A028   032 221 150 20 DD 96 JSR &96DD Check Float value (Convert if Integer)
A02B   032 250 187 20 FA BB JSR &BBFA Push FWA to Stack
A02E   032 218 150 20 DA 96 JSR &96DA Get & Check Float Value (Convert if Integer)
A031 0 165 048 A5 30 LDA &30
A033   201 135 C9 87 CMP#&87
A035 B 176 066 B0 42 BCS 66 --> &A079
A037   032 224 130 20 E0 82 JSR &82E0 Split FWA into Float/Integer parts
A03A   208 013 D0 0D BNE 13 --> &A049
A03C   032 232 187 20 E8 BB JSR &BBE8 Pop Float from Stack
A03F A 032 065 165 20 41 A5 JSR &A541 Unpack Float variable to FWA
A042 I 165 073 A5 49 LDA &49
A044   032 190 165 20 BE A5 JSR &A5BE Raise FWA to the power of the value in A
A047 , 128 044 80 2C BRA 44 --> &A075
A049   032 013 165 20 0D A5 JSR &A50D Store FWA to &0476
A04C   165 004 A5 04 LDA &04
A04E J 133 074 85 4A STA &4A
A050   165 005 A5 05 LDA &05
A052 K 133 075 85 4B STA &4B
A054 A 032 065 165 20 41 A5 JSR &A541 Unpack Float variable to FWA
A057 I 165 073 A5 49 LDA &49
A059   032 190 165 20 BE A5 JSR &A5BE Raise FWA to power value in A
A05C q 169 113 A9 71 LDA#&71
A05E   032 019 165 20 13 A5 JSR &A513 Store FWA to location &0471
A061   032 232 187 20 E8 BB JSR &BBE8 Pop Float from Stack
A064 A 032 065 165 20 41 A5 JSR &A541 Unpack float variable to FWA
A067 I 032 073 167 20 49 A7 JSR &A749 LN
A06A   032 159 169 20 9F A9 JSR &A99F Multiply FWA by &0476
A06D   032 226 169 20 E2 A9 JSR &A9E2 EXP
A070 q 169 113 A9 71 LDA#&71
A072   032 161 169 20 A1 A9 JSR &A9A1 Multiply FWA by &0400 + A
A075   169 255 A9 FF LDA#&FF
A077   128 156 80 9C BRA -100 --> &A015 Expression handler level 6
A079   032 013 165 20 0D A5 JSR &A50D Store FWA to &0476
A07C   032 216 165 20 D8 A5 JSR &A5D8 Set FWA to 1.0
A07F   128 219 80 DB BRA -37 --> &A05C

 


 Back to 8BS
Or