Homework 4 Solution - Cpr E 381 Homework 4 Solution P1. (20...

This preview shows page 1 - 3 out of 7 pages.

The preview shows page 1 - 3 out of 7 pages.
Cpr E 381 Homework 4 SolutionP1. (20 points)A.Write MIPS assembly code for the following C-program segment.I = I + J + 10 ; data movement and arithmetic instructionsF = G + H ; More of the same in the previous statementE = F – I ;if (P[E] = Q[E]) then K = L - 10; else K = L + 10;Use format like shown below.lw $rr, I; lw is opcode, $rr is a register and I is a variableadd $r1, $r2, $r3 ; add contents of registers $r2 and $r3 and store in reg $r1addi $r1, $r2, #10 ;add immediate value 10 to the contents of reg $r2 and store in reg $r1To keep the problem simple, think of each statement independently, except in case avariable is already in a register in a previous step, you do not have to read (load) it again.Also you should include comments that must include i) which register is used for whichvariable; ii) which statement in C is computed by what assembly level instructions; iii)when a result is stored in memory; and iv) any other comment you see relevant.Also use the following information.1.Assume that register $gp contains a value of 0X00100000. This value does notchange.2.Also assume that integer word variables A, B, C, D, E, F, G, H, I, J, K, and L, arestored in memory consecutively starting at location 0X000FFF00.3.Integer Array P is stored in memory starting at location 0X00101000.4.Integer Array Q is stored in memory starting at location 0X00102000.5.You should use register $s0 to $s7 for those variables that needs to be stores back inmemory (whose values gets changed).6.You should use registers $t0 to $t9 for others variables whose values does not change.7.When the program ends, all modified variables should also be stored in memory back.This study resource wasshared via CourseHero.com
lw $t0, G; Loads G into $t0, J is not needed any morelw $t1, H; Loads H into $t1add $s1, $t0, $t1; F = G + H into $s1sw $s1, F; Store new value of F// E = F – I ;sub $s0, $s1, $s0

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 7 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Spring
Professor
ZAMBRENO
Tags
Assembly Language, Following, Trigraph, sh, Digraph

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture