Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

CS 3339 : Computer Architecture SPRING 2023 Homework 02 (Q.1) Warmup 1.a) Download the SPIM MIPS simulator from https://sourceforge.net/projects/ spimsimulator/. Check if it is working by running...

1 answer below »
CS 3339 : Computer Architecture
SPRING 2023
Homework 02
(Q.1) Warmup
1.a) Download the SPIM MIPS simulator from https:
sourceforge.net/projects
spimsimulato
. Check if it is working by running one of the programs available
with this homework (see link in the assignment)1.
1.b) Implement the following C code in MIPS assembly code. Use a minimum numbe
of instructions. Assume that the values of a, b, i, and j are in registers $s0, $s1, $t0,
and $t1, respectively. Also, assume that register $s2 holds the base address of the
a
ay D.
f o r ( i =0; if o r ( j =0; j
; j++)
D[4∗ j ] = i + j ;
1.c) Initialize the variables a and b to 10 and 1, respectively, and all elements of D to
0. Simulate your program in the SPIM MIPS simulator, following step by step the
changes in the memory. At each step, take a screenshot of the simulator window,
showing the registers and memory.
1.d) How many MIPS instructions does it take to implement the code in 1.c)?
1.e) Read the documentation on System Calls available in Canvas. Implement a version
of your program that allows: (i) the user to enter values for the variables a and b;
and (ii) prints all values of D in the terminal.
(Q.2) Recursive functions
2.a) Implement the following C code in MIPS assembly.
i n t f i b ( i n t n)
{
i f (n==0)
eturn 0 ;
e l s e i f (n==1)
eturn 1 ;
e l s e
e turn f i b (n−1) + f i b (n−2);
}
1If you are in doubt, here goes a simple Youtube video with how the main steps to run your code in QtSpim:
https:
youtu.be/wlssbwmPfnc
1
https:
sourceforge.net/projects/spimsimulato
https:
sourceforge.net/projects/spimsimulato
https:
youtu.be/wlssbwmPfnc
2.b) Implement a main function that calls the fib procedure implemented in 2.a), which
initializes the variable n to 3 . Simulate your program in the SPIM MIPS simulator.
Run you program step by step observing the changes in the memory
egister. At each
step, take a screenshot of the simulator window showing the registers and memory.
2.c) Implement a version of your program that allows: (i) the user to enter a value fo
the variable n; and (ii) prints the value of fib(n) in the terminal.
(Q.3) Strings
Implement a replace(string,x,y) procedure in MIPS Assembly, which, given a string
and two characters, x and y, replaces in this string all occu
ences of the character x by
the character y. The procedure will have as arguments:
• the address of the string - string;
• the character to look for - x;
• the character for replacement - y.
For example, for the string “reblace”, if the character to look for is the character ’b’, and
the character for replacement is the character ’p’, the string must be changed to “replace”.
Simulate your program in the SPIM MIPS simulator, following step by step the changes in
memory and registers. At each each, take a a screenshot of the simulator window showing
the registers and memory.
2
Answered 2 days After Feb 15, 2023

Solution

Nidhi answered on Feb 18 2023
39 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here