Homework 2 - Chapters 2 and 3

Due: Wednesday, January 28, 2009 at 5:00pm

  1. (4 pts) Convert the following assembly into binary. Assume the code begins at memory address 80000 when calculating the jump target.
    	move	$v0, $zero
        	move	$t0, $zero	# initialize t0 to 0
    Loop:	beq	$t0, $s0, Exit	# if t0 == s0, go to Exit
    	sll	$t1, $t0, 2	# t1 = t0 * 4
    	add	$t1, $t1, $s2	# t1 = s2 + (t0 * 4)
    	lw	$t2, 0($t1)	# bring element in from memory
    	add	$v0, $v0, $t2	# v0 += t2
    	sw	$t2, 0($t1)	# send updated value back to memory
    	addi	$t0, $t0, 1	# t0++
    	j	Loop
    Exit: 
  2. (2 pts) What is the loop in Question 1 doing? Explain in words or give the equivalent C/C++ code.
  3. (2 pts) Why is it important to save the registers a0 - a3 on the stack when making recursive function calls?
  4. (2 pts) In 2.15, array subscripts are compared to pointer arithmetic for looping through an array. What is the advantage of using pointer arithmetic for the example in 2.15?
  5. (2 pts) Convert the decimal number 1054 to a 32-bit two's complement binary number.
  6. (2 pts) What decimal number does the following two's complement binary number represent? 0111 1111 0000 1010 1100 0011 1110 1110
  7. (2 pts) Humans give meaning to bit sequences. One sequence of bits can have several meanings depending on how it is interpreted. Given the following bit pattern:
        1000 1101 0010 1000 0000 0100 1011 0000
    How would you intepret it as the following:
    1. A two's complement binary number (give the decimal number)
    2. A MIPS instruction (give the human-readable assembly instruction)
  8. (4 pts) Given the following variables, show all steps to solve the following equations.
        x = 1111 1111 1111 1111 1011 0011 0101 0011
        y = 0000 0000 0000 0000 0000 0010 1101 0111
    1. x + y
    2. y - x