CMPT-150-ARC Assignment 5

Available Wednesday, July 4, 2001
Due Wednesday, July 18, 2001

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

Question 1.  Write commented HC11 code fragments to perform the following functions. You do not have to assemble or simulate these, but that would be a good way to test them. You may assume the data area is set up as follows for each function independantly (i.e. each function should operate on this data, not on the result of the last function)

        org  $3000
word1:  dw   $642C
byte1:  db   $B3
byte2:  db   $14

(a)  Swap the contents of byte1 and byte2.
(b)  Swap the high byte and low byte of word1.
(c)  Swap the high nybble and low nybble of byte2.
(d)  Subtract byte1 from byte2 and put the result in byte2.
(e)  Take the absolute value of word1 and byte1 (HC11 uses two's complement to represent negative numbers). What do you expect the results to be?
Question 2.  Implement the following pseudo-code fragment in HC11 assembly language. Assemble and simulate your code using the software available in the assignment lab. Be sure to comment your code. Submit a paper copy of your listing file (*.lst), with full documentation including justification for any design decisions you make, as well as an electronic copy of your .s19 file, which should be named a5q2.s19.  Remember to "zip" your file - your submitted .zip file should be named a5q2.zip.

/* Find the median of the array labeled "col": */
/* First, sort "col" in ascending order.  The  */
/* median is then the "center" value of the array. */
/* "col" has n entries */

for (k=n, k>0, k--)
   for (i=n-2, i>=0, i--)
      if (col[i+1] < col[i])
         {
            temp <= col[i];
            col[i] <= col[i+1];
            col[i+1] <= temp;
         }
med = col[n/2];

Hint:  There is an easy way to do "n/2" that doesn't involve the "IDIV" instruction.  Think about how the numbers are stored.

You may assume a data area set up as follows, but your program should work for any data.  Start your data area at $0000 and start your program at $0100.  You may wish to construct other data sets on which to test your program. We will test your program on a larger data set (more entries in the column) as well as this one.

      org  $0000
n:    dw   $000A    ; this column has 10 entries
med:  db   $00      ; space for the "median" result
col:  db   $08      ;col[0]
      db   $02
      db   $11
      db   $09
      db   $0A
      db   $04
      db   $03
      db   $02
      db   $0C
      db   $06      ;col[9]