base:kernal_floating_point_mathematics
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
base:kernal_floating_point_mathematics [2016-03-14 16:54] – fixed the mantissa range litwr2 | base:kernal_floating_point_mathematics [2019-10-14 07:59] – error/typo corrected silverdr | ||
---|---|---|---|
Line 30: | Line 30: | ||
**$69** holds the exponent\\ | **$69** holds the exponent\\ | ||
**$6a-$6d** holds the mantissa\\ | **$6a-$6d** holds the mantissa\\ | ||
- | **$63** holds the sign in bit 7\\ | + | **$6e** holds the sign in bit 7\\ |
Line 239: | Line 239: | ||
The first routine is the actual code. The other entries simply set up $62/$63 for you. This routine wrecks FAC2, so if it is needed, it should be loaded after the conversion. It also uselessly (from our ML standpoint) sets the data type flag at $0d. Skipping these routines and jumping straight to the normalization routine at **$b8d2** gives greater control, i.e. 24-bit and 32-bit integer inputs are possible, as are signed 8-bit inputs. For example, to convert a 24-bit number, load FAC1 with the number from the most-significant byte to the least. Store zero in the last mantissa byte, and also in the sign and rounding bytes ($66 and $70). Then set the exponent to 24 (24 + $80 = $98). Jump to $b8d2 with the carry indicating whether the result should be positive (set) or negative (clear). | The first routine is the actual code. The other entries simply set up $62/$63 for you. This routine wrecks FAC2, so if it is needed, it should be loaded after the conversion. It also uselessly (from our ML standpoint) sets the data type flag at $0d. Skipping these routines and jumping straight to the normalization routine at **$b8d2** gives greater control, i.e. 24-bit and 32-bit integer inputs are possible, as are signed 8-bit inputs. For example, to convert a 24-bit number, load FAC1 with the number from the most-significant byte to the least. Store zero in the last mantissa byte, and also in the sign and rounding bytes ($66 and $70). Then set the exponent to 24 (24 + $80 = $98). Jump to $b8d2 with the carry indicating whether the result should be positive (set) or negative (clear). | ||
+ | |||
+ | The above process is basically what the KERNAL authors did to implement the 24 bit TI variable in BASIC (though they zero the high byte instead of the low, and hence use a mantissa of $a0). | ||
+ | |||
+ | You can take advantage of their work with the following pair of calls to convert a 24 bit unsigned integer held in YXA: | ||
+ | |||
+ | sec | ||
+ | jsr $af87 ; sets mantissa to 00yyxxaa | ||
+ | jsr $af7e ; set rest of FAC1 and JMP to $b8d2 | ||
+ | |||
==== 7.4 String to FP ==== | ==== 7.4 String to FP ==== | ||
Line 423: | Line 432: | ||
lda value ;get guess based on argument | lda value ;get guess based on argument | ||
+ | clc | ||
ror | ror | ||
bcs sqrtadd | bcs sqrtadd | ||
ldx #$80 | ldx #$80 | ||
- | sta result+1 | + | stx result+1 |
sqrtadd adc #$40 | sqrtadd adc #$40 | ||
sta result | sta result |
base/kernal_floating_point_mathematics.txt · Last modified: 2020-12-06 20:48 by pararaum