|
|
ROM subroutines
Convert INT64 to DOUBLE
|
|
This subroutine has two main branches:
- when intreger argument has more than 53 bits (including the most significant one that will be hidden!), we must shift the value right to get normalized mantissa;
- othewise we'll shift argument in opposite direction until 1 will appear in the 52th - the most significant in mantissa - bit (bits 0-51 will form normalized mantissa at this moment).
In both cases the process ends when bit number 52 will be 1, and bits 53-63 are 0 - the character feature of normalized mantissa. 52th bit is not stored - so called hidden bit.
When INT64 number is equal to 25210 = 23416, its mantissa will be normalized promptly. Hexadecimal exponent in this case can be calculated as 34 + 3FF = 433 (this constant is used in the second insruction of the subroutine).
| addr |
code |
mnemonic |
action |
comments |
| EE0...1A4 | 4271 0017 | BZ $71, 0017 | branch to 200 if $71 = 0 | exit if argument is 0 |
| 1A8 | E072 4330 | SETH $72, 4330 | $72 <== 4330..00 | this value has exponent when INT64 already forms normal mantissa (53 bits) |
| 1AC | 3173 7100 | CMPI $73, $71, 00 | compare $71 with 0 and set $73 | is argument negative? |
| 1B0 | 4873 0003 | BNN $73, 0003 | branch to 1BC if $73 >= 0 | bypass if sign is plus |
| 1B4 | C571 7100 | NORI $71, $71, 00 | $71 <== NOT $71 | convert to positive value |
| 1B8 | E771 0001 | INCL $71, 0001 | $71 <== $71 + 1 |
| 1BC | E074 FFE0 | SETH $74, FFE0 | $74 <== FFE0..00 | constant to test if INT64 has more bits than mantissa |
| 1C0 | E075 0010 | SETH $75, 0010 | $75 <== 0010..00 | set the less signisicant exponent's bit |
| 1C4 | C876 7471 | AND $76, $74, $71 | $76 <== $74 AND $71 | reset 53 lower bits of argument |
| 1C8 | 4276 0004 | BZ $76, 0004 | branch to 01D8 if $76 = 0 | further if higher bits are empty |
| 1CC | 3D71 7101 | SRI $71, $71, 01 | right shift $71 | INT64 must be shifted right to form normal mantissa |
| 1D0 | 2072 7275 | ADD $72, $72, $75 | $72 <== $72 + $75 | INC exponent |
| 1D4 | F1FF FFFC | JMPB FFFFFC | branch to 01C4 | repeat the cycle |
| 1D8 | E074 FFF0 | SETH $74, FFF0 | $74 <== FFF0..00 | constant to reset mantissa except its 52th bit |
| 1DC | C876 7471 | AND $76, $74, $71 | $76 <== $74 AND $71 | clear mantissa to test the most significant bit |
| 1E0 | 4A76 0004 | BNZ $76, 0004 | branch to 1F0 | finish cycle when it is 1 |
| 1E4 | 3971 7101 | SLI $71, $71, 01 | left shift $71 | INT64 must be shifted left to form normal mantissa |
| 1E8 | 2472 7275 | SUB $72, $72, $75 | $72 <== $72 - $75 | DEC exponent |
| 1EC | F1FF FFFC | JMPB FFFFFC | branch to 1DC | repeat the cycle |
| 1F0 | 2471 7175 | SUB $71, $71, $75 | $71 <== $71 - $75 | clear the most sidnificant (hidden) bit in mantissa |
| 1F4 | C071 7172 | OR $71, $71, $72 | $71 <== $71 OR $72 | combine mantissa with exponent |
| 1F8 | 4873 0002 | BNN $73, 0002 | branch to 200 if $73 >= 0 | bypass if argument was not negative |
| 1FC | E471 8000 | INCH $71, 8000 | $71 <== $71 + 80..00 | set negative sign |
| 200 |
9F6F 6F00 | GOI $6F, $6F, 0 | return using $6F | (finish subroutine) |
Related topics:
E-MMI software
|
|
(C) 2009, Evgeny Eremin. rEd-MMI project documentation
|
|