CSCI 51A / ECE 86 - Lab #6
Lab #6 is worth 100 points.
Objectives:
Description:
Be sure that you study the structured programming techniques presented in Chapter 6 before proceeding with this lab.
Write a program that will allow a user to determine whether a specified integer is a prime number, or is a Fibonacci number. The program should prompt the user to select a function, P for prime or F for Fibonacci, and should repeat this prompt until a valid selection is made. Once the user has selected a function, the program should prompt the user to enter a number. The requested test should be performed on the number and the result printed out. Finally, the user is asked if they would like to repeat the process. When the user is finished, return control to the simulator. A sample dialog follows:
Select Prime or Fibonacci [F/P]: F Enter a number: 21 21 is a Fibonacci number Repeat? [Y/N]: Y Select Prime or Fibonacci [F/P]: N Select Prime or Fibonacci [F/P]: P Enter a number: 32 32 is not a prime number Repeat? [Y/N]: Y Select Prime or Fibonacci [F/P]: F Enter a number: 14 14 is not a Fibonacci number Repeat? [Y/N]: N
Here are a few more requirements:
- Sketch out your plan of attack using pseudocode and/or flow charts before you start coding. Make these clear and legible. After you have completed the assignment, update your design to reflect what you actually implemented. You are required to turn in both your initial and final design documents.
- Map out your register usage as you do your design. Your pseudocode and your listing file should both document register usage.
- Use structured programming techniques to code your control logic.
- Document your code using comments so that it is readable, and so that it is easily apparent to the reader how your code implements the necessary algorithms. Check your program listing for readability before you turn it in.
- Start your data area at location $2000.
- Start your instruction area at location $3000.
- Testing of a number to see if it is a prime number must be implemented with a subroutine.
- Pass in the integer to test as shown.
- Return result as shown.
************************************************************************** * PRIME * * Tests a number to see if it is a prime number * * Preconditions: * D5 - holds the number to be tested * * Postconditions: * Modifies - <list the registers your code modifies> * D0 - 0 if the number is not a prime number * 1 if the number is a prime number * * Register usage: * <document your register usage> **************************************************************************
- Testing of a number to see if it is a Fibonacci number must be implemented with a subroutine.
- Pass in the integer to test as shown.
- Return result as shown.
************************************************************************** * FIB * * Tests a number to see if it is a Fibonacci number * * Preconditions: * D5 - holds the number to be tested * * Postconditions: * Modifies - <list the registers your code modifies> * D0 - 0 if the number is not a Fibonacci number * 1 if the number is a Fibonacci number * * Register usage: * <document your register usage> **************************************************************************
- You are encouraged to design your solution using additional subroutines. Be sure to document them in a similar manner.
Here are a few hints:
- Read about and consider the following instructions: CMP, DIVU, EXG.
- given an integer, n
- to determine if n is prime, divide it by each integer between 1 and n and examine the remainder
- to determine if n is a Fibonacci number, calculate each Fibonacci number in sequence and compare it to n
- if you are having trouble, try writing these functions in a high-level language first
Turn-in Procedure
- source file
- listing file
- final design document
In WebCT, click on the Assignments icon to submit your zip file for grading.