CMPT-150-ARC Assignment 6

Available Wednesday, July 18, 2001
Due Monday, July 30, 2001

Due by 12:00 pm on Monday, July 30, in the CMPT-150-ARC drop boxes outside K9507. Make sure you put your assignment in the box labeled for CMPT-150-ARC.

PLEASE NOTE: Part of this assignment must be submitted electronically!

Question 1.  Translate the following pseudocode statements into HC11 assembly language. You do not have to assemble or simulate these. Be sure to comment your code.  For (a) and (b), how many times to you expect the loop body to execute?

(a) for(i=20; i>=0; i--){
   B++;}

(b) for(i=-300; i<20; i = i+13){
   A--;}

(c)    switch (i) {
    case 1:
       A=2;
       break;
    case 2:
       B=3;
    default:
       A=5;
       break;
  }


Question 2.  Write a subroutine, called "traparea" that will calculate the area of a trapezoid with sides of length a, b, and height h according to the following formula:

                         Area = 1/2h(a+b)
You may assume that the calling program has pushed the values of a, b, and h onto the stack, one unsigned byte each in that order, and then has pushed two bytes onto the stack as room for the return value, before executing "jsr traparea".  You may assume that a and b are limited such that the sum (a+b) will not exceed FFh.

You should place your subroutine at memory $0800 so that we can use a standard shell to test the subroutines. There is an example calling program available here, and you should make sure your subroutine works with this calling program. Submit a paper copy of the .lst file of your subroutine only and your design process, as well as an electronic copy of the .s19 file of your subroutine only, which should be named "a6q2.s19" and zipped into a file called "a6q2.zip".  (note that your .asm file should be called a6q2.asm if you want it to work with the supplied calling progam.)