CSCI 255
Introduction to Embedded Systems
Fall 2011
Lab #5 - Dip switch calculator
Create an assembly language program that calculates various things based on the decimal value specified by the dip switches on the 8052 educational board.
The dip switch represent a 8-bit binary number.
We will consider the ON position to be binary 1.
The switch labeled 1 is the most signficant bit.
So for example, if all switches are off except 6 and 8, the decimal number is 4 + 1 = 5.
You should implement three subroutines that do the following calculations and display the result on the onboard LEDs:
Even - Light up LED D0 if the value is even. Note that the value 0 is even.
Evenly divisible by 3 - Light up LED D1 if the value is evenly divisible by 3. Note that the value 0 is evenly divisible by 3.
Prime - Light up LED D2 if the value is prime. Note that the values 0 and 1 are not prime.
To determine if the number is prime, you may use a simple algorithm.
For example, you can check to see if a number N is prime by checking the remainder of N divided by
N-1, N-2, ..., 2. If N is not evenly divisible by any of these numbers, it is a prime number.
Extra credit. Implement a fourth subroutine that computes the odd parity of the 8-bit value and displays it on D3. That is, D3 should light up if an odd number of switches are 1. Implement a fifth subroutine that determines if the number is a perfect square (e.g. 4, 9, 16, etc) and lights up D4 if it is.
Submission.
Submit your program to the Lab #5 dropbox on Moodle.
Be sure your submitted source file has the required header with your name, username, and a description of the program.
Your program will be graded on functionality, readability and elegance.