CS 273 Lab 3: Writing HC11 Assembly Code

Dept. of Computer Science, NMSU

Fall 2006

Due Date: Next class after your lab session.

Part 1

The assembly language program that you copied and ran in Lab 2 is very simple, and just does the following computations:

testv = param2

result = param2 + 5 + param1

In this lab, copy the test.asm file to lab3a.asm using the cp command, and then modify lab3a.asm to do the following computations:

testv = param2 + 12

result = param1 - param2 + 7

Hint: Similar to the “ABA” instruction that the example program uses, there is an “SBA” instruction that means subtract B from A. There is not a subtract A from B instruction!

Questions:

  1. How many cycles does your program take to run?
  2. What are the final values of testv and result?

Part 2

Write an assembly program named lab3b.asm that, given one corner and the center of a rectangle, computes the other three corners. You might declare the given data (the one corner and the center) as constants such as:

Xcnr1    FCB    9  
Ycnr1    FCB    0  
Xcntr    FCB   12  
Ycntr    FCB    5

Then, you will declare six variables to hold the X and Y coordinates of the other three corners. At the end of your program, the values must be correct in memory, not just in registers. You can assume that all values (including those you will compute) are 8-bit positive integer values. You do not need to deal with fractional coordinates.

Hints: It doesn’t matter which corner you are given, the computation is the same. Think about the diagonal across the rectangle that starts at the corner you are given. The center of the rectangle is the midpoint of that line, thus, you can use the midpoint formula and a little algebra to calculate the corner at the other side of the diagonal. Once you have that, the rest is easy. Work it out on paper before you start programming. You do not need to multiply or divide anything – adds and subtracts are enough. Also make sure you pay attention to how you use the HC11 registers.

Assemble your source code file to generate the machine code file. Run your program using the simulator.

Questions:

  1. What are the addresses of the memory locations that hold your six variables (coordinates for the three corners)? Be sure to say which variable is at which address.
  2. What are the final values (in decimal) of your variables for the input values in the example above?
  3. What is the final time count for your program’s execution?
  4. Even though we said that values are all positive, let’s try an experiment. Change the input values to be a corner at (6,4) and a center at (2,3), and run your program.
    1. by hand, figure out what the coordinates should be (in decimal) and write these down.
    2. what are the final values when you run your program (both in hex and in decimal)?

Lab Turn-in

For this lab, you must hand in the following:

  1. lab3a.asm
  2. lab3b.asm
  3. Lab report, with answers to all the questions.

    Lab report must be named “LastName-Lab3.???” and contains your report and answers to the questions.

    Please write the lab report using the template available online at

    or,

Submit these through the web submission page at:

http://www.cs.nmsu.edu/~joemsong/273/upload/