QZ1-sol - addi $a0 $a0 1 Ans The instruction memory is accessed four times(as there are four instructions and the data memory is accessed

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
1 CSE 341: Computer Organization Spring 2011 Solution to QZ #1 Week of 2/14/11 Quiz 1 Duration: 25 minutes Question 1: (5 points) Write the following sequence of code into MIPS assembler: x = x + y + z - q; Assume that x, y, z, q are stored in registers $s1-$s4. Ans: The MIPS assembly sequence is as follows: add $t0, $s1, $s2 add $t1, $t0, $s3 sub $s1, $t1, $s4 Question 2: (5 points) In the snippet of MIPS assembler code below, how many times is instruction memory accessed? How many times is data memory accessed? (Count only accesses to memory, not registers.) lw $v1, 0($a0) addi $v0, $v0, 1 sw $v1, 0($a1)
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: addi $a0, $a0, 1 Ans: The instruction memory is accessed four times (as there are four instructions) and the data memory is accessed twice (once for the lw instruction and another time for the sw instruction). Question 3: (5 points) Instead of using a special hardware multiplier, it is possible to multiply two numbers using shift and add instructions. Suppose we want to put 5 times the value of $s0 into $s1, ignoring any overflow that may occur. Show a minimal sequence of MIPS instructions for doing this without using a multiply instruction. Ans: sll $s1, $s0, 2 addu $s1, $s0, $s1...
View Full Document

This document was uploaded on 10/20/2011.

Ask a homework question - tutors are online