Question
Write a complete Keil MDK project comprising a main program and a subroutine. The subroutine must be called fact and should calculate the factorial of
Write a complete Keil MDK project comprising a main program and a subroutine.
The subroutine must be called fact and should calculate the factorial of the number passed to it in R0. The subroutine must be recursive. Zero marks will be awarded for a non-recursive solution.
The purpose of the main program is to demonstrate and test the subroutine.
Calculations must be done in 64-bit unsigned arithmetic and the result must be returned in R0 & R1, with the most significant 32 bits in R0 and the least significant 32 bits in R1.
If any error occurs, the C bit of the CPSR must be set and a result of 0 returned in R0 & R1. If there are no errors, the C bit must be clear.
The main program should use the subroutine four times:
- Calculate the factorial of 5.
- Calculate the factorial of 14.
- Calculate the factorial of 20.
- Calculate the factorial of 30.
Each result should be stored, by the main program, as a 64-bit result in RAM, starting at 0x40000000. Do this by reserving four 8-byte spaces at the start of the read-write area.
Note that the ARM7 does not do 64-bit arithmetic youll have to somehow make use of 32-bit calculations to do 64-bit arithmetic.
Do not use repeated addition to implement multiplication. Zero marks will be awarded for a solution that uses repeated addition.
Please create a plain text file called qanda.txt ( for Questions AND Answers) and include it in your project folder. In it, please answer the following questions very briefly (one or two sentences each, max):
- What does well behaved mean in the context of subroutines?
- Explain how/why your subroutine is well behaved.
- How would you test that your subroutine is well behaved?
- Why is using repeated addition to implement multiplication such a bad idea?
- What would happen to the program if a very large number of recursive calls were made, i.e. if there was very "deep" recursion?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started