Computer Science 281

 

First Hour Exam

 

 

 

Name _________________

 

 

 

 

 

 

 

 

 

 

 

 

Monday, Feb. 25

2:00

100 Pts.


I.          For the following two questions, assume an 8 bit word with two's complement representation for negative integers.

 

            a.            (10 pts.)  Give answers in hex.

 

                        What does the internal representation of 18 (base 10)

                        look like?

 

 

 

 

 

                        What does the internal representation of -18

                        look like?

 

 

 

            b.         (15 pts.)  Perform the following arithmetic operations,

                        indicating any changes to the N, V, C, and Z bits of the

                        status register.

 

                         7F63

                        -52A7

                        ------

 

 

 

 

 

 

                         7F63

                        + 182

                        -----

 

 

 


II.         (20 pts.)            Suppose that we have

 

            (A0) = $1000            (D0) = 42

            (A1) = $4260            (D1) = 127            (D3) = $12345678

            ($0FFC) = -14            ($425C) = 27

            ($1000) = 95            ($4260) = 100

            ($1004) = 34            ($4264) = 3045

            ($2000) = $FEDCBA01

 

            What changes if the following instructions are executed?  Indicate only memory locations or registers changed, and treat each question independently.

 

            a.            move.l            #24,D0

 

 

 

            b.            move.l            (A1),-(A2)

 

 

 

            c.            move.l            (A1)+,$4260

 

 

 

            d.            move.l            #$1000,$1000

 

 

 

            e.            tst.b                  (A1)+

 

 

 

            f.            move.b            $2000,D3            (careful with this one!)


III.       (15 pts.)           Hand assemble the following program segment, using the short form (one word) for the branch.

 

            loop:     move.l  $2E06,D3

                        add.w               D3,-(A4)

                        bne                   loop

 

 

 

 

 

 

 

 

 

 

IV.       Short code segments

 

            a.         (5 pts.) Write the code to clear bit 3 of D2

 

 

 

 

b.            (10 pts. - a repeat until question)            Write the code to shift the word stored at location $1000 right until a 1 has been shifted out (do not worry about the fact that this would cause an infinite loop if the number is initially zero).

 


V.        (25 pts.)           Write a complete assembly language program which will add up the elements of an array of 10 elements, print the sum, and the message "big" if the sum is > 100, and the message "small" if it is not.  Implement the array using the dc.l directive (pick any numbers you care to use).  The format for the write and write2 functions (write2 with one argument) are given by

 

            procedure write(var format : string);

            procedure write2(var format : string; var arg : integer; 0);