Re: Problem with tiny HP-16C program - can you debug this? Message #9 Posted by Richard B on 7 July 2008, 1:46 p.m., in response to message #7 by Richard B
Here is the same debugged code to switch between Float and Int. This time it is integrated with routines for INT and RND.
All suggestions very welcome.
Instructions:
GSB A Float to Int
GSB 9 Int to Float
GSB B INT
GSB D RND
Step ListKey Mnemo Comments
001 43,22,2 g LBL 2 Subroutine to store sign
002 43,5,2 g CF 2
003 43 2 g x<0
004 43,4,2 g SF 2
005 43 8 g ABS
006 43 21 g RTN
007 43,22,3 g LBL 3 Subroutine to round
008 42 49 f EEX
009 9 9
010 40 +
011 43 36 g LSTx
012 30 -
013 43 21 g RTN
014 43,22,a g LBL A Float to Int
015 21 2 GSB 2
016 23 HEX Convert
017 43 8 g ABS
018 44 32 STO I
019 34 x<>y
020 43,22,1 g LBL 1
021 43 b g ASR
022 43 23 g DSZ
023 22 1 GTO 1
024 0 0 Set wordsize to 64
025 42 44 f WSIZE
026 43,4,3 g SF 3
027 43,22,4 g LBL 4
028 43,6,2 g F? 2 Restore sign
029 49 CHS
030 43,4,3 g SF 3 Show leading zeroes
031 43 21 g RTN
032 43,22,b g LBL B INT
033 21 2 GSB 2
034 21 3 GSB 3
035 43 3 g x>y Adjust rounded result by 1
036 1 1
037 0 0
038 36 Enter
039 1 1
040 0 0
041 10 /
042 30 -
043 22 4 GTO 4
044 43,22,d g LBL D RND
045 21 2 GSB 2
046 21 3 GSB 3
047 22 4 GTO 4
048 43,22,9 g LBL 9 Int to Float
049 0 0
050 42,45,4 f FLOAT 4 Number of decimal places
051 43 21 g RTN
|