CS2340 – (Solution)

$ 35.00
Category:

Description

CS/SE 2340 – Assignment#2
1- 1-For the following C statements, what are the corresponding MIPS assembly code? Assume that the variables f, g, h, i, and j are assigned to registers $s0, $s1, $s2, $s3, and $s4, respectively. Assume that the base address of the arrays A and B are in registers $s6 and $s7, respectively.
a. B[4] = A[4+2i] ;
b. B[4+4i] = A[4] ;
c. B[8i+2] = A[2g+h] +h;
2-If we assume we place the following MIPS code starting at location 4000 in memory, what is the MIPS machine code for this code? (Please show binary and decimal value for each field) Assume that i is associated to registers $t0, size is associated to registers $a1, and the base of the array save is in $a0. Please also explain each instruction and specify its type ( R format, I format, or J format). Finally convert the following code to C.

* Please change the first instruction to add $t0, $zero, $zero
3-Write MIPS assembly for the following function. Assume N is passed to your function in register $a0. Your output should be in register $v0 at the end of your function. Note: You must implement this function recursively. The purpose of this assignment is to learn how to manipulate the stack correctly in MIPS.
int Myfun (int N)
{
if (N>0) return ( Myfun(N-1) + N ); else return 0
}
Please explain each instruction with a comment. Please submit your source code and a screenshot that shows the registers with correct output value for N=10, i.e., Myfun(10) returns 55 .
4-Translate the following program to MIPS assembly program (Please explain each instruction in your code by a comment and submit a .asm file)

5-Translate the following program to MIPS assembly program (Please explain each instruction in your code by a comment and submit a .asm file)

Reviews

There are no reviews yet.

Be the first to review “CS2340 – (Solution)”

Your email address will not be published. Required fields are marked *