17-06-2014, 11:32 AM
Lab #5 Programming Problems
Programming Problems.doc (Size: 54 KB / Downloads: 50)
INTRODUCTION
The following example demonstrates how problems are stated in this lab.
Problem: PARITY
Write a 68000 program called PARITY to compute the parity of a 16-bit word. Parity is "odd" if an odd number of bits are 1 in the data, and parity is "even" if an even number of bits are 1. The data is stored in memory as a word-sized variable DATA at address $9000. The result is a byte variable RESULT at address $9002. Store $FF in RESULT for odd parity, and $00 in RESULT for even parity.
Sample Conditions:
Before:
Address Contents
9000 36C2
9002 ?
After:
9000 36C2
9002 FF
The sample conditions show the source data and the memory location where the result is stored. The result of the addition is shown in the "after" contents of memory location $9002. This allows the programmer to work through the problem by hand to verify the objective.
Below is one possible solution to this problem:
PROCEDURE
1. Enter the example program in a file called PARITY.SRC. Assemble the program, and transfer to the 68KMB. Test it with different values at $9000 until you understand the operation of the program.
2. The program executes in a loop with 16 iterations, which is a lot to trace through by hand. To investigate the program operation, you will use a temporary breakpoint. Read about the GT command on page 392 of your textbook.
3. Store $A000 at location $9000. Since the low bits are all 0, the loop will be mostly finished the first time it reaches the NOT.B D1 line. Using GT, run the program until it reaches that NOT.B D1.
4. Use MON68K's single-step facility (TR) to trace through the rest of the execution of the program, while completing the following table. Notice that in filling out the table, we think of D0 as a 16-bit word, D1 as a byte, and D2 simply as a counter.
CONCLUSION
Having completed this lab, students are capable of writing small 68000 programs in assembly language