Computer Science 281

 

Second Hour Exam

 

 

 

Name _________________

 

 

 

 

 

 

 

 

 

 

 

 

Monday, April 8

2:00

100 Pts.


I.          (10 pts.)

            Suppose that

            (1000) = 10                 (A5) = 1004

            (1004) = 38                 (A3) = 1008

            (1008) = -57                (D2) = -8

 

            (assume base 10 for all the above)

 

            What is the effect of each of the following instructions (assume that each instruction is independent of all the others: i.e., treat each question individually).  Indicate any memory locations and data/address registers that are changed.

 

a.         move.l  (a5)+,-(a3)

 

 

 

 

b.         move.l  (a5)+,-(a5)

 

 

 

 

 

c.         clr.l                   4(a5)

 

 

 

d.         clr.l                   -1000(pc)        (assume that the address

                                                of this instruction is 2000: careful

                                                with this one)

 

 

 

 

            e.         clr.l                   4(a5,d2.l)


II.         (10 pts.)           Suppose that we have

 

            type student_rec = record

                        student_name : packed array [1..10] of char;

                        exam1, exam2 : integer;

                        exam_average : integer

            end

 

            Suppose that A0 contains the address of one of these records and that exam1, exam2, and exam_average are stored as longwords.  Write the statements necessary to add exam1 and exam2 and store the truncated average in exam_average.  Feel free to use any registers you want to without saving/restoring them.


III.       Stack problems (10 pts each).  Assume that A5 points to the top of an integer (longword) stack with the usual conventions.  Without including any code to check for empty/full stacks, write complete procedures to

 

a.         Push a number onto the stack (argument passed by value)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

b.         Swap the top two entries on the stack (no arguments)


IV.       Functions and procedures:

 

a.         (20 pts.)           Implement the following procedure carefully in assembly language.  Store the local variable on the stack.  What is the effect of the procedure?  What was intended, do you think?

 

procedure nonsense(a : integer; var b : integer);

            var c : integer;

            begin

            c := a;

            a := b;

            b := c

            end

 


b.         (15 pts.)           Suppose that we have

 

                type name_rec = record

                                name : packed array [1..11] of char;

                                next : ^name_rec

                end;

 

            The name field is always 11 characters, and the last characters are always a line field followed by a null character (so that you can use printf to print the name).  The field next contains the longword address of the next field.  The value of NIL is zero.  A Pascal program to list a linked list is as follows:

 

                procedure list(this_one : ^name_rec)

                                begin

                                if this_one <> NIL then

                                                begin

                                                writeln(this_one^.name);

                                                list(this_one^.next)

                                                end

                                end;

 

                Implement this in assembly language.


V.        More arithmetic (10 pts.)

 

            Write the code necessary to see if the long integer stored in a evenly divides the long integer stored in b.  If it does, put a 0 in D0, if not, put a -1 in D0.

 

 

 

 

 

 

 

 

 

 

 

VI.       Data representation).

 

            a.         (5 pts.) Suppose that we have

 

                        NUM:  DC.W              $1252

 

            What is the value of the packed decimal stored in the word at NUM?

 

 

 

 

 

b.         (10 pts.)           What is the internal representation of the single precision floating point number -12.75?  Give your answer in hex.