Section 11: Branching and Looping168
How it works: Each time you execute GOTHAM, the program prompts you for the number of years, which is stored in R00. This is used by DSE as the loop control value. The year (1624) is stored in R01 and the final amount is stored in R02.
Each time through the loop, 6% of the amount is computed and added to the amount in R02 and 1 year is added to the year in R01. The DSE subtracts one from the R00-register; if the value in R00 is not then zero, execution is transferred back to LBL 01, and the loop is executed again.
When R00 becomes zero, execution skips to the RCL 01 instruction in line 18. The year is then recalled and displayed (formatted in FIX 0), and the final amount is recalled and displayed (formatted in FIX 2).
Note that ISG and DSE can be used to increment and decrement any number that the HP-41C can display. However, the decimal portion of the control number will be affected by large numbers.
For example, the number 999,950.50055, when incremented by 55 using ISG would become 100,005.5005. The initial number was incremented by 55. But since the new number cannot be fully displayed, the decimal portion of the number was truncated. The next increment would be by 50, not 55. And when the number becomes 999,955.5005, the next number would be 1,000,005.500, thus truncated the decimal portion of the number again. Since no increment value is present, the next increment would be by 01, not 50.
Problem:
  1. Write a program that will count from zero up to a limit using the ISG function, and then, in the same program, count back down to zero using the DSE function. The program should contain two loops, the first one counting up, the second one counting down. Use the flowchart on the following page to help you.