Date: Tue, 05 Nov 1996 00:32:12 GMT Server: NCSA/1.5 Content-type: text/html Last-modified: Fri, 11 Oct 1996 14:55:46 GMT Content-length: 3975 CS 354 - Quiz #3
CS 354
Fall 1996
Section 2
SOLUTION
Quiz #3 for Friday October 11
3 questions, 25 points total

1. (9 points) Do the following 8-bit two's complement arithmetic calculations. Show all work. Indicate if overflow occurs by writing the word "overflow" next to the calculated result. Give a 16-bit result for the multiplication.

    01011110                    11000000
  + 11011000                  + 10001111
 -----------                 -----------
    00110110                    01001111 OVERFLOW




    01010010                    01110111
  - 10011000                  x 11110001
 -----------                 -----------
  change to addition             negative multiplier, so change problem         
				    (and sign extend partial products)
    01100111                                10001001 (-119)
	+  1                              x 00001111 (  15)
    --------                             -----------
    01101000                        1111111110001001
                                    1111111100010010
                                    1111111000100100
                                  + 1111110001001000
    01010010                      ------------------
  + 01101000                        1111100100000111 (-1785)
 -----------
    10111010  OVERFLOW

2. (9 points) Give an algorithm and then write a SAL code fragment (not a whole program) that does sign magnitude multiplication (x * y -> z). Variables x and y are given values elsewhere in the program. They contain 32-bit sign magnitude representations. The result of the multiplication goes in variable z, which is also 32 bits and is initialized (elsewhere in the program) to 0. The code should ignore the possiblility of overflow from 32 bits. It is OK to modify variables x and y.