Question

In: Computer Science

The code below is giving an arithmetic overflow. Correct the below given the below code, so...

The code below is giving an arithmetic overflow. Correct the below given the below code, so that the value of s0 is printed before calling the function fun1, inside the function Fun1 and after returning from Fun1 in main. Upload the corrected .asm or .s file in the drop box.


.text

main:

addi $s0,$zero,2

jal Disp

jal Fun1

jal Disp

j Exit

Fun1:

addi $sp,$sp,-4

sw $s0,0($sp)

addi $s0,$s0,15

jal Disp

lw $s0,0($sp)

addi $sp,$sp,4

jr $ra

Disp:

li $v0,1

move $a0,$s0

syscall

jr $ra

Exit:

li $v0,10

syscall

Solutions

Expert Solution

Hope this will help you. If you have any doubt please let me know.

Please go through all the notes.

Notes: 1) All most all coding part is given; I just stored the return address of Function1 into stack before calling a disp function, because when we are calling a function disp the value of $ra register is changed, and that address is remained in $ra register. To return from function 1 we need an original value that is stored in $ra register when function 1 is called from main to return to main. Hence before calling a function disp in function 1 we have to store the $ra register.

2) note that the value of $s0 is stored in stack pointer in function1 at the return time we are retrieving a $s0 register from stack pointer hence the value of $s0 register before, during and after function 1 is 2, 17 and 2 respectively( other-wise $s0’s value is preserved throughout program and it will return 2,17,17 respectively)

3) Please let me know if you find a difficulty in this

4) Screenshot of output is also attached.

-------------------Coding part---------------------

.text

main:
addi $s0,$zero,2 #setting $s0=2
jal Disp # calling a function Display
jal Fun1 #calling a function 1
jal Disp # calling a function disp again
j Exit # exit the program

Fun1: # function1 def begin
addi $sp,$sp,-4 # adjusting stack pointer
sw $s0,0($sp) # storing $s0's value in stack pointer
addi $s0,$s0,15 # adding 15 into $s0
addi $sp,$sp,-4 # adjusting stack pointer to store a return address of function 1
sw $ra,0($sp) # storing reaturn address in stack pointer
jal Disp # calling a dispaly function
lw $ra,0($sp) # loading a return address in $ra
addi $sp,$sp,4 # adjusting a stack pointer
lw $s0,0($sp) #loading a value in $s0
addi $sp,$sp,4 # adjusting a stack pointer
jr $ra # return

Disp: #display

li $v0,1 #for printing integer
move $a0,$s0 #printing value of$s0
syscall
jr $ra #return address

Exit: # exit
li $v0,10
syscall

--------------------Screen shot------------------------------


Related Solutions

The cross section of a non- overflow gravity dam is as given below: Top width                   -   ...
The cross section of a non- overflow gravity dam is as given below: Top width                   -    12 m R.L of top of dam       -    + 215 m R.L of bottom of dam -    + 104 m FRL                            -    + 212 m No tail water Upstream face is vertical Downstream face is vertical till a R.L of + 205 m, after which it has a slope of 0.7 H:1 V up to the base Drain holes are located at a distance...
how to correct this java code so that i get the correct day of week? and...
how to correct this java code so that i get the correct day of week? and test the year public static void main(String[] args) {        //               Scanner s = new Scanner(System.in); //needed info //year month, day int year, month, dayOfMonth; // add day of week , century yr int dayOfWeek, century, yearOfCentury;    //user inputs year System.out.print("Enter year: (example, 2020):"); year = s.nextInt(); //user inputs month by number System.out.print("Enter month: 1-12:"); month = s.nextInt();...
Complete the below code so that your program generates a random walk on the given graph....
Complete the below code so that your program generates a random walk on the given graph. The length of your walk should also be random. /******************************************************************/ #include <stdio.h> #include <stdlib.h> #include <time.h> typedef struct NODE_s *NODE; typedef struct NODE_s{ char name; NODE link[10]; }NODE_t[1]; #define nodeA 0 #define nodeB 1 #define nodeC 2 #define nodeD 3 #define nodeE 4 #define nodeF 5 int main() { srandom(time(NULL)); //printf("%d\n", random()); NODE_t node[6]; node[nodeA]->name = 'A'; node[nodeB]->name = 'B'; node[nodeC]->name = 'C'; node[nodeD]->name...
What is the impact of an outlier in the determination of an arithmetic mean? Show by giving an example?
What is the impact of an outlier in the determination of an arithmetic mean? Show by giving an example?
I want the code below to be edited: Rather than giving the input string inside the...
I want the code below to be edited: Rather than giving the input string inside the code, I want the program to ask the user for an input and calculate and complete this code. I have pasted the actual code below, Please edit the input section only so that I can input any string or any sentence as I like. The program must ask the user that "Enter a string/sentence" and take the data to calculate the Huffman code. #include...
Answer the given statements as True or False. If the statement is false, correct it so...
Answer the given statements as True or False. If the statement is false, correct it so it becomes a true statement. 1. The neutral axis can be found at a distance ‘y’ (where y>0) from the centroidal axis of a member. 2. The centre of curvature can be found at a radial distance (rho) from the neutral axis of a member in pure bending. 3. When developing generalized equations for stress transformations, we must consider stresses on only the horizontal...
C++ Q2.   Given the code as below. Which statement is correct? int myAry[100]; for(int i=0; i<100;...
C++ Q2.   Given the code as below. Which statement is correct? int myAry[100]; for(int i=0; i<100; i++) myAry = i + 2; for(int i=100; i>0; i--) cout << myAry[i] << '\t'; The first for loop assigns myAry 99 values and the null character. The second for loop prints out myAry elements backwards. The index in the second for loop is out of bounds. Only the first loop needs the null character. Q3. A value returning function that takes one parameter,...
1.The below code has some errors, correct the errors and post the working code. Scanner console...
1.The below code has some errors, correct the errors and post the working code. Scanner console = new Scanner(System.in); System.out.print("Type your name: "); String name = console.nextString(); name = toUpperCase(); System.out.println(name + " has " + name.Length() + " letters"); Sample Ouptut: Type your name: John JOHN has 4 letters    2. Write a code that it reads the user's first and last name (read in the entire line as a single string), then print the last name   followed by...
Requirements: Code in C++. With given information, write the solution to this problem so that it...
Requirements: Code in C++. With given information, write the solution to this problem so that it is understandable to someone with basic knowledge of C++ (ex: only keep basic libraries, keep coding shortcuts to a minimum). Also leave comments in the code (plz), the logic behind solving this problem if possible, and explanation of what the keys to solving this problem is and how to run test cases to ensure correctness of code. Problem: For this problem you will compute...
Given the values of So given below in J/mol K and the values of ΔHfo given...
Given the values of So given below in J/mol K and the values of ΔHfo given in kJ/mol, calculate the value of ΔGo in kJ for the combustion of 1 mole of propane to form carbon dioxide and gaseous water at 298 K. S (C3H8(g)) = 274 S (O2(g)) = 209 S (CO2(g)) = 216 S (H2O(g)) = 181 ΔHfo (C3H8(g)) = -105 ΔHfo (CO2(g)) = -394 ΔHfo (H2O(g)) = -225
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT