{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

CDA3101-F11-HW2-KEY

# CDA3101-F11-HW2-KEY - 1 CDA3101 Organization of Computer...

This preview shows pages 1–3. Sign up to view the full content.

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

View Full Document
2 2.3. slli \$s2, \$s3, 2 shift the contents of register \$s3 left by 2 bits and store the result in register \$s2 2.4. beq \$s4, \$s5, three if the contents of register s4 equal the contents of register s5, then jump to the label "three". Otherwise, continue on to the next statement Part II. MIPS Programming 3. Writing Simple MIPS Programs (16 pts total) 3.1. (6 pts: 2pt each) Write 3 MIPS code fragments that each multiply a number by eight using (i) shifting only, (ii) addition only, and (iii) multiplication by a constant Shifting: slli \$s0, \$s0, 3 #shift contents of s0 left 3 bits Addition: add \$s0, \$s1, \$s1 #s0 <- s1 + s1 = 2*s1 add \$s0, \$s0, \$s0 #s0 <- s0 + s0 = 2*s0 = 4*s1 add \$s0, \$s0, \$s0 #s0 <- s0 + s0 = 2*s0 = 8*s1 Multiply: addi \$t0, \$0, 8 #put 8 into t0 mul \$s0, \$s0, t0 #s0 <- s0 * t0 = s0 * 8 3.2. (5 pts) Write a MIPS program that executes the following high-level code fragment (initialize x = 0; define registers and their contents; comment all code): for i = 1 to 21 by 4 do: { y := x + 5 * i ; x := 6 * y i } Let’s begin by diagramming the program execution (a few steps suffice): Iteration i x y (1 st stmt) x (2 nd stmt) 1 1 0 5 = 0 + 5 * 1
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 8

CDA3101-F11-HW2-KEY - 1 CDA3101 Organization of Computer...

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

View Full Document
Ask a homework question - tutors are online