User Tools

Site Tools


base:kernal_floating_point_mathematics

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
base:kernal_floating_point_mathematics [2019-10-14 09:45] – [Zero Page Locations] silverdrbase:kernal_floating_point_mathematics [2020-12-06 20:48] (current) – [7.1 FP to integer] pararaum
Line 129: Line 129:
  
 **$bb0f** = Divide the memory contents pointed to by A/Y (low/high) by FAC1.\\ **$bb0f** = Divide the memory contents pointed to by A/Y (low/high) by FAC1.\\
-**$bb12** = Entry if FAC2 already loaded. Accumulator must load FAC1 exponent ($61) beforehand to set the zero flag.+**$bb12** = Entry if FAC2 already loaded. Accumulator must load FAC1 exponent ($61) beforehand to set the zero flag. Sign comparison is not performed and ARISGN byte at $6f is not set, which has to be accounted for when using this entry point. Hard to debug sign errors may occur otherwise.
  
 Divides FAC2 by FAC1, leaving the quotient in FAC1, and the remainder in FAC2. Divides FAC2 by FAC1, leaving the quotient in FAC1, and the remainder in FAC2.
Line 224: Line 224:
 ==== 7.1 FP to integer ==== ==== 7.1 FP to integer ====
  
 +There seems to be only a single routine in the ROMs, see Lothar Englisch, "The Advanced Machine Language Book", Abacus Software, 1984, p 28. IT is located at $BC9B and converts the floating-point value in the FAC (the fractional portion is truncated) into a whole number. The four mantissa bytes ($62-$65) contain the value in a big-endian representation.
 ==== 7.2 FP to string ==== ==== 7.2 FP to string ====
  
Line 234: Line 235:
 **$bc44** = Convert signed 16-bit integer held in FAC1 at $63 (lo) and $62 (high) to FP\\ **$bc44** = Convert signed 16-bit integer held in FAC1 at $63 (lo) and $62 (high) to FP\\
 **$b391** = Convert signed 16-bit integer held in Y/A (lo/high) to a FP number in FAC1\\ **$b391** = Convert signed 16-bit integer held in Y/A (lo/high) to a FP number in FAC1\\
-**$bc3c** = Convert unsigned 8-bit integer held in A to a FP number in FAC1\\+**$bc3c** = Convert signed 8-bit integer held in A to a FP number in FAC1\\
 **$b3a2** = Convert unsigned 8-bit integer held in Y to a FP number in FAC1 **$b3a2** = Convert unsigned 8-bit integer held in Y to a FP number in FAC1
  
 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).+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 an exponent 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: You can take advantage of their work with the following pair of calls to convert a 24 bit unsigned integer held in YXA:
base/kernal_floating_point_mathematics.txt · Last modified: 2020-12-06 20:48 by pararaum