Re: 8/60 -> HMS Message #46 Posted by Thomas Klemm on 4 May 2013, 6:45 a.m., in response to message #1 by PGILLET
Since I was curious how the HP-41C handles this transformation I had a glance at the source code.
It all boils down to the following steps:
The subroutine HMSMP is called twice. In between the pointer PT is moved 2 places to the right (DEC PT):
544 716 1 GOSUB HMSMP
544 717 0
545 720 1724 DEC PT
546 721 HMS160 1724 DEC PT
547 LEGAL
548 722 1 GOSUB HMSMP
This subroutine HMSMP multiplies the register C with 0.6 (unless S5 is set):
565 747 HMSMP 412 A=C WPT ; A = C
566 750 1712 C SR WPT ; shift right C => C = 0.1 * A
567 751 752 C=C+C WPT ; C = 0.2 * A
568 752 752 C=C+C WPT ; C = 0.4 * A
569 753 1112 C=A-C WPT ; C = A - 0.4 * A = 0.6 * A
570 754 214 ?S5=1
571 755 63 GONC HMSM20 ( 763)
572 756 16 A=0 W ; clear the whole word
573 757 406 A=C X ; copy the last digit
574 760 1016 C=A+C W ; adding the last digit rounds the result
575 761 106 C=0 X ; clear the last digit
576 762 1740 RTN
Let's have a look at how this works for the example 0.21:
P
C: 02100000000000
A=C WPT A: 02100000000000
C SR WPT C: 00210000000000
C=C+C WPT C: 00420000000000
C=C+C WPT C: 00840000000000
C=A-C WPT C: 01260000000000
I'll skip the rounding here and just continue to the 2nd call of HMSMP.
Please note that the pointer P is now shifted 2 places to the right:
545 720 1724 DEC PT
546 721 HMS160 1724 DEC PT
Thus the operations won't affect digits left to P:
P
C: 01260000000000
A=C WPT A: 00060000000000
C SR WPT C: 01206000000000
C=C+C WPT C: 01212000000000
C=C+C WPT C: 01224000000000
C=A-C WPT C: 01236000000000
Thus we end up with the result 0.1236 interpreted as 0:12'36".
Now let's have a look at what's happening with 8/60:
P
C: 01333333333000
A=C WPT A: 01333333333000
C SR WPT C: 00133333333300
C=C+C WPT C: 00266666666600
C=C+C WPT C: 00533333333200
C=A-C WPT C: 00799999999800
The next steps deal with the rounding:
P
C: 00799999999800
A=0 W A: 00000000000000
A=C X A: 00000000000800
C=A+C W C: 00800000000600
C=0 X C: 00800000000000
The next call to HMSMP doesn't change anything on that result.
Thus we end up with 0.08 which is interpreted as 0:08'00".
That's the point where the value 7999999998 is rounded to 9 places.
Kind regards
Thomas
VASM ROM ASSEMBLY
510 ENTRY XTOHRS
511 ENTRY HMSMP
512 ENTRY HMSDV
************************************************
* IF TO H.MMSS, THEN S5=1 *
* IF TO H.DDDD, THEN S5=0 *
************************************************
517 662 XTOHRS 1372 ? C#0 M
518 663 1640 RTN NC
519 664 416 A=C W
520 665 216 B=A W
521 666 1046 C=C+1 X
522 667 1046 C=C+1 X
523 670 406 A=C X
524 671 1534 PT= 12
525 672 506 A=A+C X
526 673 107 GOC HMS140 ( 703)
527 674 HMS110 1724 DEC PT
528 675 1624 ? PT= 0
529 676 33 GONC HMS130 ( 701)
530 677 HMS120 316 C=B W
531 700 1740 RTN
532 701 HMS130 1146 C=C-1 X
533 702 1723 GONC HMS110 ( 674)
534 703 HMS140 116 C=0 W
535 704 332 C=B M
536 705 214 ?S5=1
537 706 223 GONC HRS100 ( 730)
538 707 1734 INC PT
539 710 1324 ? PT= 13
540 711 43 GONC HMS150 ( 715)
541 712 1 GOSUB HMSMP
541 713 0
542 714 53 GOTO HMS160 ( 721)
543 715 HMS150 1734 INC PT
544 716 1 GOSUB HMSMP
544 717 0
545 720 1724 DEC PT
546 721 HMS160 1724 DEC PT
547 LEGAL
548 722 1 GOSUB HMSMP
548 723 0
549 724 416 A=C W
550 725 316 C=B W
551 726 HMS170 1 GOLONG MPY150
551 727 2
552 730 HRS100 16 A=0 W
553 731 1 GOSUB HMSDV
553 732 0
554 733 1734 INC PT
555 734 1324 ? PT= 13
556 735 27 GOC HRS120 ( 737)
557 736 1734 INC PT
558 737 HRS120 1 GOSUB HMSDV
558 740 0
559 741 1756 A SL W
560 742 516 A=A+C W
561 743 356 BC EX W
562 744 1623 GOTO HMS170 ( 726)
563 745 HMSDV 1712 C SR WPT
564 746 1012 C=A+C WPT
565 747 HMSMP 412 A=C WPT
566 750 1712 C SR WPT
567 751 752 C=C+C WPT
568 752 752 C=C+C WPT
569 753 1112 C=A-C WPT
570 754 214 ?S5=1
571 755 63 GONC HMSM20 ( 763)
572 756 16 A=0 W
573 757 406 A=C X
574 760 1016 C=A+C W
575 761 106 C=0 X
576 762 1740 RTN
577 763 HMSM20 512 A=A+C WPT
578 764 1712 C SR WPT
579 765 1352 ? C#0 WPT
580 766 1757 GOC HMSM20 ( 763)
581 767 1740 RTN
Edited: 4 May 2013, 7:06 a.m.
|