top decor
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...204E072 3FE0SETH $72, 3FE0$72 <== 3FE0..000.5
2080471 7172FADD $71, $71, $72$71 <== $71 + $72argument + 0.5: to provide rounding

Convert DOUBLE to INT64 (trunk)

addr code mnemonic action comments
EE0...20C4271 0012BZ $71, 0012branch to 254??? if $71 = 0exit if argument is 0; sorry, it's the bug! Address must be set to 258!!!
2103173 7100CMPI $73, $71, 00compare $71 with 0 and set $73is argument negative?
214EC71 8000ANDNH $71, 8000$71 <== $71 AND (NOT 80..00)reset sign bit
2183F72 7134SRUI $72, $71, 34$72 <== shift right unsigned on 34 bitsget exponent (3416 = 5210) to $72
21CE374 0433SETL $74, 0433$74 <== 433exponent - 433; I do this to determine if argument is < 252 or not
2202472 7274SUB $72, $72, $74$72 <== $72 - $74
224EC71 7FF0ANDNH $71, 7FF0$71 <== AND (NOT 7FF0..00)reset exponent and get mantissa
228E471 0010INCH $71, 0010$71 <== $71 + 0010..00restore hidden 1 (now mantissa has 53 bits!)
22C4872 0005BNN $72, 0005branch to 0240 if $72 >= 0branch if exponent >= 5210
230C572 7200NORI $72, $72, 00$72 <== NOT $72convert to positive value (number of bits for further shift)
234E772 0001INCL $72, 0001$72 <== $72 + 1
2383C71 7172SR $71, $71, $72$71 <== right shift $71 on $72 bitsget INT64 shifting mantissa right
23CF000 0004JMP 000004branch to 24Cbypass alternative branch
2403174 720ACMPI $74, $72, 0Acompare $72 with 0ah and set $74(exponent - 52) > 10?
2444474 0006BP $74, 0006branch 25C if $74 > 0if exponent was more than 63 - overflow
2483871 7172SL $71, $71, $72$71 <== left shift $71 on $72 bitsget INT64 shifting mantissa left
24C4873 0003BNN $73, 0003branch to 258 if $73 >= 0if argument was not negative - exit
250C571 7100NORI $71, $71, 00$71 <== NOT $71convert negative integer value to complement-on-two
254E771 0001INCL $71, 0001$71 <== $71 + 1
2589F6F 6F00GOI $6F, $6F, 00return using $6Fnormal subroutine ending
25C2174 6F00ADDI $74, $6F, 00$74 <== $6Fsaving return address (no use)
2609F6F 7030GOI $6F, $70, 30call 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
27C0000 0000TRAP 0jump to systemruntime error: panic ending

back previous page next page forward


Related topics:

E-MMI software
 

  (C) 2009, Evgeny Eremin. rEd-MMI project documentation