|
|
ROM subroutines
Convert DOUBLE to INT64
(with rounding or without)
|
|
This subroutine is reverse to the previous one. It also has two branches whether argument is greater than 25210 = 23416 or not: it determines the direction of mantissa's shift. In opposite to INT64 to DOUBLE conversion, this subroutine may generate overflow.
Working with this Web-page, I found two unessential bugs: one is incorrect branch in the case when argument is zero, and then the deranged text after overflow (must be "real ==> int" but not "int ==> real"!)
Convert DOUBLE to INT64 (round)
| addr |
code |
mnemonic |
action |
comments |
| EE0...204 | E072 3FE0 | SETH $72, 3FE0 | $72 <== 3FE0..00 | 0.5 |
| 208 | 0471 7172 | FADD $71, $71, $72 | $71 <== $71 + $72 | argument + 0.5: to provide rounding |
Convert DOUBLE to INT64 (trunk)
| addr |
code |
mnemonic |
action |
comments |
| EE0...20C | 4271 0012 | BZ $71, 0012 | branch to 254??? if $71 = 0 | exit if argument is 0;
sorry, it's the bug! Address must be set to 258!!! |
| 210 | 3173 7100 | CMPI $73, $71, 00 | compare $71 with 0 and set $73 | is argument negative? |
| 214 | EC71 8000 | ANDNH $71, 8000 | $71 <== $71 AND (NOT 80..00) | reset sign bit |
| 218 | 3F72 7134 | SRUI $72, $71, 34 | $72 <== shift right unsigned on 34 bits | get exponent (3416 = 5210) to $72 |
| 21C | E374 0433 | SETL $74, 0433 | $74 <== 433 | exponent - 433; I do this to determine if argument is < 252 or not |
| 220 | 2472 7274 | SUB $72, $72, $74 | $72 <== $72 - $74 |
| 224 | EC71 7FF0 | ANDNH $71, 7FF0 | $71 <== AND (NOT 7FF0..00) | reset exponent and get mantissa |
| 228 | E471 0010 | INCH $71, 0010 | $71 <== $71 + 0010..00 | restore hidden 1 (now mantissa has 53 bits!) |
| 22C | 4872 0005 | BNN $72, 0005 | branch to 0240 if $72 >= 0 | branch if exponent >= 5210 |
| 230 | C572 7200 | NORI $72, $72, 00 | $72 <== NOT $72 | convert to positive value (number of bits for further shift) |
| 234 | E772 0001 | INCL $72, 0001 | $72 <== $72 + 1 |
| 238 | 3C71 7172 | SR $71, $71, $72 | $71 <== right shift $71 on $72 bits | get INT64 shifting mantissa right |
| 23C | F000 0004 | JMP 000004 | branch to 24C | bypass alternative branch |
| 240 | 3174 720A | CMPI $74, $72, 0A | compare $72 with 0ah and set $74 | (exponent - 52) > 10? |
| 244 | 4474 0006 | BP $74, 0006 | branch 25C if $74 > 0 | if exponent was more than 63 - overflow |
| 248 | 3871 7172 | SL $71, $71, $72 | $71 <== left shift $71 on $72 bits | get INT64 shifting mantissa left |
| 24C | 4873 0003 | BNN $73, 0003 | branch to 258 if $73 >= 0 | if argument was not negative - exit |
| 250 | C571 7100 | NORI $71, $71, 00 | $71 <== NOT $71 | convert negative integer value to complement-on-two |
| 254 | E771 0001 | INCL $71, 0001 | $71 <== $71 + 1 |
| 258 | 9F6F 6F00 | GOI $6F, $6F, 00 | return using $6F | normal subroutine ending |
| 25C | 2174 6F00 | ADDI $74, $6F, 00 | $74 <== $6F | saving return address (no use) |
| 260 | 9F6F 7030 | GOI $6F, $70, 30 | call subroutine $70 + 30, return - $6F |
runaway to subroutine of printing text about overflow (emergency exit) |
264 268 26C 270 274 278
|
1769 6E74 203D 3D3E 2072 6561 6C20 6F76
6572 666C 6F77 0A0D
|
#17 int ==> rea l ov erfl ow #0A #0D |
"int ==> real overflow" |
text from 17h symbols |
| 27C | 0000 0000 | TRAP 0 | jump to system | runtime error: panic ending |
Related topics:
E-MMI software
|
|
(C) 2009, Evgeny Eremin. rEd-MMI project documentation
|
|