CDA3101-F11-Quiz2-KEY

CDA3101-F11-Quiz2-KEY - CDA 3101 Fall 2011 Quiz 2 Answer...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CDA 3101 Fall 2011 Quiz 2 Answer Key Given: MIPS Instructions CPI mult = 5 cycles; add, addi, sub, subi = 3 cycles; lw, sw = 2 cycles; mflo + all others = 1 cycle 1) Write a simple MIPS code fragment to compute z = 3x + y – 2w, for 0 < w,x,y < 100 Comment all code to get full credit!! MIPS CODE: #Note: There are several possible implementations which will work. This is one # implementation. li $s0, 1 #w is represented by $s0. 1 cycle. li $s1, 1 #x is represented by $s1. 1 cycle. li $s2, 1 #y is represented by $s2. 1 cycle. li $s3, 0 #z is represented by $s3. 1 cycle. li $t1, 3 #store the value 3 in a temporary to help compute 3x. 1 cycle. LOOP: #main loop for our code fragment slti $t2, $s0, 100 #check the w < 100 condition. 1 cycle. beq $t2, $0, EXIT #exit the loop if w>=100. 1 cycle. slti $t2, $s1, 100 #check the x < 100 condition. 1 cycle. beq $t2, $0, EXIT #exit the loop if x>=100. 1 cycle. slti $t2, $s2, 100 #check the y < 100 condition. 1 cycle.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 2

CDA3101-F11-Quiz2-KEY - CDA 3101 Fall 2011 Quiz 2 Answer...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online