Laboratory 04 Conditional Codes and Prime Number Tester
This exercise investigates conditional code and branches use in ARM Cortex-M3 assembly language program and use of Keil MDK-ARM debugger. The objective of this exercise is familiarization with Cortex-M3 conditional codes through a prime-number test design and programming.
Prelab
Read through this web page, http://www.wikihow.com/Check-if-a-Number-Is-Prime for prime number testing algorithm method 1. Method 1.1 to 1.5 is the algorithm we will use in this lab. Google and find all prime factors smaller than 100 and write them down. Use this algorithm to test if the number 9997 and 1259 are prime numbers and write down their square roots to be used for programming. (Hint: The square root to be used for testing should be rounded up, i.e., take the ceiling function)
Draw (by hand or using Computer CAD tools, such as Visio) a flowchart for the testing algorithm. In this lab, we assume that the test integer is smaller than 100,000, (if it is greater than 100,000, your code simply returns to indicate that it is a non-prime number).
Include a snapshot of your hand-drawn flowchart or computer generated one and all other prelab requirements in your lab report.
Lab Procedure
1. Create a new directory lab04 and Keil MDK-ARM project for this lab exercise, name it as lab04.
2. Following the guidelines listed below, write a properly commented and properly formatted Cortex-M3 assembly language program to test if the number 9997 is a prime number. a. The number 9997 and square root must be declared using assembler directives EQU NUM, and NUMSQT.
NUM EQU 9997
NUMSQRT EQU 100
b. The result is saved in register R7, R7=0, indicating a non-prime number; R7=1, indicating a prime number.
c. Get a screen of your simulation results (Ctrl-Alt-Print Screen) to show than R7=0 for the number 9997.
d. Change the number to 1259 and corresponding square root, run the steps a)