5-Translate the following C program to MIPS assembly program (Please ex- plain each instruction in your code by a comment and submit a .asm file) #include using namespace std; // function to return sum of elements // in an array of size n int sum(int arr, int n) { int sum · 0; // initialize sum // Iterate through all elements // and add them to sum for (int i = 0; i < n; i++) sum +- arr[i]; return sum; } // Driver code int main()

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
J
ill
UTD Fall 2022 CS 2340 Assignme X
2 of 2
CS 2340- Fall 2022- Assignment# X +
File C:/Users/rubai/OneDrive/UTD%20Fall%202022%20CS%202340%20Assignment%202.pdf
68°F
Cloudy
#include <bits/stdc++.h>
using namespace std;
5-Translate the following C program to MIPS assembly program (Please ex-
plain each instruction in your code by a comment and submit a .asm file)
// function to return sum of elements
// in an array of size n
int sum(int arr[], int n)
{
int sum= 0; // initialize sum
// Iterate through all elements
// and add them to sum
for (int i = 0; i < n; i++)
sum += arr[i];
}
return sum;
}
// Driver code
int main()
{
int arr[] = {12, 3, 4, 15};
int n = sizeof(arr) / sizeof(arr[0]);
cout << "Sum of given array is " << sum(arr, n);
return 0;
CD |
Q
T
H
PDF
J
ENG
I
Bo
60
3:53 PM
10/16/2022
x
:
Transcribed Image Text:J ill UTD Fall 2022 CS 2340 Assignme X 2 of 2 CS 2340- Fall 2022- Assignment# X + File C:/Users/rubai/OneDrive/UTD%20Fall%202022%20CS%202340%20Assignment%202.pdf 68°F Cloudy #include <bits/stdc++.h> using namespace std; 5-Translate the following C program to MIPS assembly program (Please ex- plain each instruction in your code by a comment and submit a .asm file) // function to return sum of elements // in an array of size n int sum(int arr[], int n) { int sum= 0; // initialize sum // Iterate through all elements // and add them to sum for (int i = 0; i < n; i++) sum += arr[i]; } return sum; } // Driver code int main() { int arr[] = {12, 3, 4, 15}; int n = sizeof(arr) / sizeof(arr[0]); cout << "Sum of given array is " << sum(arr, n); return 0; CD | Q T H PDF J ENG I Bo 60 3:53 PM 10/16/2022 x :
Expert Solution
Step 1

Answer:

.data

str1: .asciiz "Hello"

str2: .asciiz "mars"

msg: .asciiz "String after the concatenate: "

.text

main:

#load the address str1 to $a0

la $a0,str1

#initialize $t0 with 0

li $t0,0

#loop to find the length of str1

#$t0 stores the length of str1

loop1:

#load byte of $a0 to $t1

lb $t1,0($a0)

#branch for equal.If $t1 equal to 0,jump to label stop1

beq $t1,0,stop1

addi $t0,$t0,1 #increase the count

addi $a0,$a0,1 #increase the address

#jump to label loop1

j loop1

stop1:

#load the address of str2 to $a1

la $a1,str2

#loop2 concatenate the each element in str2 to str1

loop2:

lb $t2,0($a1) #load character in str2 to $t2

sb $t2,0($a0) #store value in $t2 to str1

beq $t2,0,stop2

addi $a1,$a1,1 #increase the address of str2

addi $a0,$a0,1 #increase the address of str1

j loop2

stop2:

#syscall for print string is $v0 = 4

#syscall to termiante the program is $v0 = 10

#print the message

li $v0, 4

la $a0, msg

syscall

#print the concatenated string

li $v0,4

la $a0,str1

syscall

#termiante the program

li $v0, 10

syscall

 

Computer Science homework question answer, step 1, image 1

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education