CS/COE 447 Homework 3, Spring 2007 ================================== PLEASE BE SURE TO INCLUDE YOUR NAME ON YOUR ANSWERS. Please submit directly to the grader's mailbox: Grader: Michel Hanna - 6th floor mail room, SENNOTT SQUARE Q0 [4 points] Translate these decimal numbers into binary. Use 8 bits for the fraction (i.e., 8 bits after the radix point). 21.375 3.75 Q1.A [24 points] Consider the following MIPS code: What values do $t0-$t5 and $s0-$s5 have after this code is executed? (You can check your answers in the simulator, but you should work through this on paper first, without a calculator.) .text li $t0,-11 li $t1,0x0800000f addu $t2,$t0,$t1 add $t3,$t0,$t1 slt $t4,$t0,$t1 sltu $t5,$t0,$t1 li $s0,0x80000000 li $s1,2 mult $s0,$s1 mflo $s2 mfhi $s3 multu $s0,$s1 mflo $s4 mfhi $s5 Q1.B [5 points] Does this instruction from the program result in overflow? Please explain your answer. addu $t2,$t0,$t1 Q1.C [5 points] Does this instruction from the program result in overflow? Please explain your answer. add $t3,$t0,$t1 Q2 [16 points] "Overflow" means that the result of an operation does not fit in the allotted number of bits "unsigned overflow": the result doesn't fit, viewing the numbers as unsigned numbers "signed overflow": the result doesn't fit, viewing the numbers as signed numbers This question uses 8-bit (1-byte) binary numbers. Perform the indicated operations and fill in the tables. (For example, in the first table, you should fill in the sum in binary, and then say what 00001010, 11111101, and their sum are in decimal, viewing them as signed numbers). decimal, viewing the is there signed numbers as signed overflow? 00001010 +11111101 ---------- decimal, viewing the is there unsigned numbers as unsigned overflow? 00001010 +11111101 ---------- decimal, viewing the is there signed numbers as signed overflow? 01100100 +00110010 ---------- decimal, viewing the is there unsigned numbers as unsigned overflow? 01100100 +00110010 ---------- decimal, viewing the is there signed numbers as signed overflow? 10011100 +11001110 ---------- decimal, viewing the is there unsigned numbers as unsigned overflow? 10011100 +11001110 ---------- decimal, viewing the is there signed numbers as signed overflow? 00000001 +00000001 ---------- decimal, viewing the is there unsigned numbers as unsigned overflow? 00000001 +00000001 ---------- Q3 [6 points] Exercises 4.1, 4.2, 4.3 Q4 [6 points] Exercise 4.7 Q5 [6 points] Exercise 4.8 Q6 [7 points] Exercise 4.11 Q7 [7 points] Exercise 4.12 Q8 [7 points] Exercise 4.35 (for more practice; find the pdf file on the course schedule) Q9 [7 points] Exercise 4.38 (for more practice; find the pdf file on the course schedule) Q10 Self-study question: give the machine code for the beq instruction in the following code (first in binary, then in hex). Then, check your answer in the assembler. .data array: .word 3,4,5,5,5,6 .text li $s3,1 # s3 = i - 1 li $s5,5 la $s6,array loop: addi $s3,$s3,1 sll $t1,$s3,2 add $t1,$t1,$s6 lw $t0,0($t1) beq $t0,$s5,loop exit: Q11 Self-study question: be sure to do all the examples covered in lecture yourself (floating point numbers, division algorithm, etc), checking your answers against the answers given in class. Q12 Self-study question to understand the multiplication hardware in Figure 3.7; slides 15 and 16 of Chapter 3 Part 2 lecture notes. Assume the datapath is 8 bits, so that we will multiply an 8-bit multiplicand and an 8-bit multiplier. We will work with 17 * 19 = 323, *in binary*. We will perform unsigned multiplication (like the operation performed by multu in MIPS). First, perform the operation (in binary) as a human would. Write down all 8 lines to be added, including the lines of 0's, to help you see the correspondence with what the circuit is doing. Now perform the same operation human-style, but add the lines as you go along. Now trace the algorithm from slides 15 and 16 of the Chapter 3 Part 2 lecture notes, and compare this to your human operations above, to understand what is going on.