CS320 Assignment #2
Date assigned: 2/27/04
Date due: 3/5/04
Points: 35

Part I

You are to use what you've learned to write a Real Mode assembly language program that will swap the values in two variables (each a word in size) in three different ways. i.e. Show how the values in two word size variables can be swapped in three unique ways.

To do this, in your data segment set up six word-size variables as follows: m1v1, m1v2, m2v1, m2v2, m3v1, m3v2. For the first solution in this program use the variables m1v1 and m1v2, for the second solution in the same program use the variables m2v1 and m2v2 and for the third solution in the same program use the variables m3v1 and m3v2. Assign each pair of variables the values 1 and -1 respectively.

To insure that your program works correctly, execute the program through the use of the debugger (debug) and then check the memory locations of each pair of variables. If your program worked correctly, the values in each pair of variables will be swapped. Next execute your program using Codeview and step through your code showing the variables in a watch window and watch the values change.

On or before the assignment is due, bring in a hard copy solution of the single assembly language program fully documented as discussed in class. Further, demo your program using both debuggers to insure its correctness. This process will take about 15 minutes per person so, don't wait until the last day.

To successfully complete this assignment, you will go through the following steps:
1) Understand this assignment fully before writing any code.
2) Identify inputs (if any).
3) Identify outputs (if any).
4) Write an algorithm which contains the three solutions to the problem.
5) Using Visual Studio 6.0, code the algorithm in assembly language (SWAP.ASM).
6) Then assemble the assembly language code (SWAP.OBJ).
7) Then link the code to produce an executable module (SWAP.EXE).
8) Using DEBUG from a DOS shell, load and execute the machine code examining the data segment for the correctness of the solution (DEBUG SWAP.EXE).
(9) Finally, using Codeview, execute the program showing the variables m1v1, m1v2, m2v1, m2v2, m3v1, m3v2 in a watch window. Step through the program one instruction at a time and watch the variables change.

Note: Get an early start!! Although the assembly language solution should not be too difficult, there are many things you must become familiar with including , debug, and Codeview. This should pull all of the pieces from chapters 1 and 2 together nicely.


Part II

I would like you to examine the following C program segment:

sum = 0;
for (int i = 1; i; i++)
{
  sum += i;
}
printf ("Sum = %i \n i = %i", sum, i);
Explain fully why this loop does or does not terminate. Include with your discussion exactly what the microprocessor does at each step so that I know you know what is going on. You can use Visual Studio 6.0 to look at the assembly language for this code. Include a copy of the assembly language to aid with your discussion. Also, explain why the output is what it is.


©Douglas J. Ryan/ryandj@pacificu.edu