1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Phoenix [80]
3 years ago
5

Translate the following C++ program to MIPS assembly program. *Please explain each instruction of your code by a comment and sub

mit a .asm file*#include using namespace std; void myfunction(int arr[], int n) { int writes = 0; for(int start = 0; start <= n-2; start++){ int item = arr[start]; int pos = start; for(int i = start+1; i< n; i++) if (arr[i]
Computers and Technology
1 answer:
maw [93]3 years ago
5 0

Answer:

Check the explanation

Explanation:

ASM of MIPS gcc 5.4:

myfunction(int*, int):

       addiu   $sp,$sp,-56

       sw      $31,52($sp)

       sw      $fp,48($sp)

       move    $fp,$sp

       sw      $4,56($fp)

       sw      $5,60($fp)

       sw      $0,24($fp)

       sw      $0,28($fp)

$L16:

       lw      $2,60($fp)

       nop

       addiu   $3,$2,-2

       lw      $2,28($fp)

       nop

       slt     $2,$3,$2

       bne     $2,$0,$L17

       nop

       lw      $2,28($fp)

       nop

       sll     $2,$2,2

       lw      $3,56($fp)

       nop

       addu    $2,$3,$2

       lw      $2,0($2)

       nop

       sw      $2,44($fp)

       lw      $2,28($fp)

       nop

       sw      $2,32($fp)

       lw      $2,28($fp)

       nop

       addiu $2,$2,1

       sw      $2,36($fp)

$L5:

       lw      $3,36($fp)

       lw      $2,60($fp)

       nop

       slt     $2,$3,$2

       beq     $2,$0,$L3

       nop

       lw      $2,36($fp)

       nop

       sll     $2,$2,2

       lw      $3,56($fp)

       nop

       addu    $2,$3,$2

       lw      $3,0($2)

       lw      $2,44($fp)

       nop

       slt     $2,$3,$2

       beq     $2,$0,$L4

       nop

       lw      $2,32($fp)

       nop

       addiu   $2,$2,1

       sw      $2,32($fp)

$L4:

       lw      $2,36($fp)

       nop

       addiu   $2,$2,1

       sw      $2,36($fp)

       b       $L5

       nop

$L3:

       lw      $3,32($fp)

       lw      $2,28($fp)

       nop

       beq     $3,$2,$L18

       nop

$L6:

       lw      $2,32($fp)

       nop

       sll     $2,$2,2

       lw      $3,56($fp)

       nop

       addu    $2,$3,$2

       lw      $3,0($2)

       lw      $2,44($fp)

       nop

       bne     $3,$2,$L8

       nop

       lw      $2,32($fp)

       nop

       addiu   $2,$2,1

       sw      $2,32($fp)

       b       $L6

       nop

$L8:

       lw      $3,32($fp)

       lw      $2,28($fp)

       nop

       beq     $3,$2,$L9

       nop

       lw      $2,32($fp)

       nop

       sll     $2,$2,2

       lw      $3,56($fp)

       nop

       addu    $3,$3,$2

       addiu   $2,$fp,44

       move    $5,$3

       move    $4,$2

       jal     void std::swap<int>(int&, int&)

       nop

       lw      $2,24($fp)

       nop

       addiu   $2,$2,1

       sw      $2,24($fp)

$L9:

       lw      $3,32($fp)

       lw      $2,28($fp)

       nop

       beq     $3,$2,$L7

       nop

       lw      $2,28($fp)

       nop

       sw      $2,32($fp)

       lw      $2,28($fp)

       nop

       addiu   $2,$2,1

       sw      $2,40($fp)

$L13:

       lw      $3,40($fp)

       lw      $2,60($fp)

       nop

       slt     $2,$3,$2

       beq     $2,$0,$L11

       nop

       lw      $2,40($fp)

     nop

       sll     $2,$2,2

       lw      $3,56($fp)

       nop

       addu    $2,$3,$2

       lw      $3,0($2)

       lw      $2,44($fp)

       nop

       slt     $2,$3,$2

       beq     $2,$0,$L12

       nop

       lw      $2,32($fp)

       nop

       addiu   $2,$2,1

       sw      $2,32($fp)

$L12:

       lw      $2,40($fp)

       nop

       addiu   $2,$2,1

       sw      $2,40($fp)

       b       $L13

       nop

$L11:

       lw      $2,32($fp)

       nop

       sll     $2,$2,2

       lw      $3,56($fp)

       nop

       addu    $2,$3,$2

       lw      $3,0($2)

       lw      $2,44($fp)

       nop

       bne     $3,$2,$L14

       nop

       lw      $2,32($fp)

       nop

       addiu   $2,$2,1

       sw      $2,32($fp)

       b       $L11

       nop

$L14:

       lw      $2,32($fp)

       nop

       sll     $2,$2,2

       lw      $3,56($fp)

       nop

       addu    $2,$3,$2

       lw      $3,0($2)

       lw      $2,44($fp)

       nop

       beq     $3,$2,$L9

       nop

       lw      $2,32($fp)

       nop

       sll     $2,$2,2

       lw      $3,56($fp)

       nop

       addu    $3,$3,$2

       addiu   $2,$fp,44

       move    $5,$3

       move    $4,$2

       jal     void std::swap<int>(int&, int&)

       nop

       lw      $2,24($fp)

       nop

       addiu   $2,$2,1

       sw      $2,24($fp)

       b       $L9

       nop

$L18:

       nop

$L7:

       lw      $2,28($fp)

       nop

       addiu   $2,$2,1

       sw      $2,28($fp)

       b       $L16

       nop

$L17:

       nop

       move    $sp,$fp

       lw      $31,52($sp)

       lw      $fp,48($sp)

       addiu   $sp,$sp,56

       j       $31

       nop

$LC0:

       .ascii "array:\000"

$LC1:

       .ascii " \000"

main:

       addiu   $sp,$sp,-72

       sw      $31,68($sp)

       sw      $fp,64($sp)

       move    $fp,$sp

       li      $2,1                        # 0x1

       sw      $2,32($fp)

       li      $2,8                        # 0x8

       sw      $2,36($fp)

       li      $2,3                        # 0x3

       sw      $2,40($fp)

       li      $2,9                        # 0x9

       sw      $2,44($fp)

       li      $2,10                 # 0xa

       sw      $2,48($fp)

       li      $2,2                        # 0x2

       sw      $2,52($fp)

       li      $2,4                        # 0x4

       sw      $2,56($fp)

       li      $2,7                        # 0x7

       sw      $2,28($fp)

       addiu   $2,$fp,32

       lw      $5,28($fp)

       move    $4,$2

       jal     myfunction(int*, int)

       nop

       lui     $2,%hi($LC0)

       addiu   $5,$2,%lo($LC0)

       lui     $2,%hi(_ZSt4cout)

       addiu   $4,$2,%lo(_ZSt4cout)

       jal     std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)

       nop

       move    $3,$2

       lui     $2,%hi(_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)

       addiu   $5,$2,%lo(_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)

       move    $4,$3

       jal     std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))

       nop

       sw      $0,24($fp)

$L21:

       lw      $3,24($fp)

       lw      $2,28($fp)

       nop

       slt     $2,$3,$2

       beq     $2,$0,$L20

       nop

       lw      $2,24($fp)

       nop

       sll     $2,$2,2

       addiu   $3,$fp,24

       addu    $2,$3,$2

       lw      $2,8($2)

       nop

       move    $5,$2

       lui     $2,%hi(_ZSt4cout)

       addiu   $4,$2,%lo(_ZSt4cout)

       jal     std::basic_ostream<char, std::char_traits<char> >::operator<<(int)

       nop

       move    $3,$2

       lui     $2,%hi($LC1)

       addiu   $5,$2,%lo($LC1)

       move    $4,$3

       jal     std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)

       nop

       lw      $2,24($fp)

       nop

       addiu   $2,$2,1

       sw      $2,24($fp)

       b       $L21

       nop

$L20:

       move    $2,$0

       move    $sp,$fp

       lw      $31,68($sp)

       lw      $fp,64($sp)

       addiu   $sp,$sp,72

       j       $31

       nop

void std::swap<int>(int&, int&):

       addiu   $sp,$sp,-24

       sw      $fp,20($sp)

       move    $fp,$sp

       sw      $4,24($fp)

       sw      $5,28($fp)

       lw      $2,24($fp)

       nop

       lw      $2,0($2)

       nop

       sw      $2,8($fp)

       lw      $2,28($fp)

       nop

       lw      $3,0($2)

       lw      $2,24($fp)

       nop

       sw      $3,0($2)

       lw      $2,28($fp)

       lw      $3,8($fp)

       nop

       sw      $3,0($2)

       nop

       move    $sp,$fp

       lw      $fp,20($sp)

       addiu   $sp,$sp,24

       j       $31

       nop

__static_initialization_and_destruction_0(int, int):

       addiu   $sp,$sp,-32

       sw      $31,28($sp)

       sw      $fp,24($sp)

      move    $fp,$sp

       sw      $4,32($fp)

       sw      $5,36($fp)

       lw      $3,32($fp)

       li      $2,1                        # 0x1

       bne     $3,$2,$L26

       nop

       lw      $3,36($fp)

       li      $2,65535                    # 0xffff

       bne     $3,$2,$L26

       nop

       lui     $2,%hi(_ZStL8__ioinit)

       addiu   $4,$2,%lo(_ZStL8__ioinit)

       jal     std::ios_base::Init::Init() [complete object constructor]

       nop

       lui     $2,%hi(__dso_handle)

       addiu   $6,$2,%lo(__dso_handle)

       lui     $2,%hi(_ZStL8__ioinit)

       addiu   $5,$2,%lo(_ZStL8__ioinit)

       lui     $2,%hi(_ZNSt8ios_base4InitD1Ev)

       addiu   $4,$2,%lo(_ZNSt8ios_base4InitD1Ev)

       jal     __cxa_atexit

       nop

$L26:

       nop

       move    $sp,$fp

       lw      $31,28($sp)

       lw      $fp,24($sp)

       addiu   $sp,$sp,32

       j       $31

       nop

You might be interested in
I need help now I really do what is the answer thank you
Svetradugi [14.3K]
The answer is c
just replace the y with the y value and the x with the x value
4 0
3 years ago
Gps receivers are commonly used by individuals to determine their geographic location while hiking and to obtain driving directi
soldier1979 [14.2K]
I think it is true also.
7 0
3 years ago
Write a program to test your functions as follows: Obtain a random number seed from the command line of your program using comma
Iteru [2.4K]

Answer:

Please find the code attached.

Explanation:

Please find the attached code in pictures.

7 0
3 years ago
true or false: the larger your sample size for a survey, the more likely it is that you will draw false conclusions from your in
Alex_Xolod [135]
False. The more people you have the more likely you will have true conclusions...
6 0
3 years ago
Write a class called Course that represents a course taken at a school. Represent each student using the modified Student class
Vinvika [58]

Answer:

The code is given below with its appropriate output

Explanation:

//Student.java

import java.io.BufferedReader;

import java.io.FileReader;

import java.io.IOException;

import java.util.Scanner;

public class Student {

public String firstName;

public String lastName;

public float[] marks;

Scanner scanner = new Scanner(System.in);

public Student(String firstName, String lastName) {

this.firstName = firstName;

this.lastName = lastName;

}

public void getdetail() {

System.out.println("enter only five marks");

marks = new float[5];

int count = 0;

for (int i = 0; i < 5; i++) {

float mark = 0;

++count;

if (count <= 5) {

System.out.println("enter score " + count);

mark = scanner.nextFloat();

if (mark >= 0.0 && mark <= 100.0)

marks[i] = mark;

else {

System.out.println("you entered mark is invalid");

marks[i] = 0;

}

} else

System.out.println(" maximum is five only");

}

}

public void tostring() {

System.out.println("firstname :" + "\t" + firstName + "\t" + "lastname :"

+ "\t" + lastName + "\n" + "the marks are");

int count = 0;

for (float mark : marks) {

count++;

System.out.println("the mark of " + count + " is " + mark);

}

}

public void Averagecal() {

float sum = 0.0f;

for (float mark : marks) {

sum = sum + mark;

}

float avg = sum / 5;

System.out.println("average of a student is " + avg);

}

}

//Course.java

import java.io.*;

import java.io.BufferedReader;

import java.io.FileReader;

import java.io.IOException;

import java.util.Scanner;

public class Course {

public String courseName;

public int number;

Student[] students;

Scanner scanner = new Scanner(System.in);

public Course(String courseName) {

this.courseName = courseName;

}

public void addStudents() {

System.out

.println("how many no of students you want to add for this particular course");

int count = scanner.nextInt();

students = new Student[count];

for (int i = 0; i < count; i++) {

System.out.println("enter the first name");

String fname = scanner.next();

System.out.println("enter the last name");

String lname = scanner.next();

Student s = new Student(fname, lname);

s.getdetail();

s.tostring();

s.Averagecal();

students[i] = s;

}

}

public void roll() {

int count = 0;

for (Student stud : students) {

count++;

}

System.out.println("the no of students in this " + courseName

+ " course is " + count);

}

}

//Driver.java

import java.io.BufferedReader;

import java.io.FileReader;

import java.io.IOException;

import java.util.Scanner;

public class Driver {

public static void main(String[] args) {

Course course = new Course("java");

course.addStudents();

course.roll();

}

}

<u>output: </u>

C:\Users\Daniel\Desktop\New folder>javac Student.java

C:\Users\Danie;\Desktop\New folder>javac Course.java

C:\Users\Daniel\Desktop\New folder>javac Driver.java

C:\Users\Daniel\Desktop\New folder>java Driver

how many no of students you want to add for this particular course ?

1

enter the first name

john

enter the last name

rich

enter only five marks

enter score 1

89

enter score 2

91

enter score 3

85

enter score 4

78

enter score 5

96

firstname : john lastname : rich

the marks are

the mark of 1 is 89.0

the mark of 2 is 91.0

the mark of 3 is 85.0

the mark of 4 is 78.0

the mark of 5 is 96.0

average of a student is 87.8

the no of students in this java course is 1

C:\Users\Ravi\Desktop\New folder>

3 0
3 years ago
Other questions:
  • Click to review the online content. Then answer the question(s) below, using complete sentences. Scroll down to view additional
    8·1 answer
  • Develop a Java program that determines the gross pay for an employee. The company pays hourly rate for the first 40 hours worked
    8·1 answer
  • Information flows:
    11·1 answer
  • Help me plase will give brainliest
    12·2 answers
  • A file with a com extension is most likely to be a(n) ___ file.
    13·2 answers
  • What time is spellrd the same forwards and backwards​
    11·1 answer
  • Cloud-based services can open doors to leveraging Artificial Intelligence (AI) without dramatically increasing risk. Which clien
    9·1 answer
  • What are input masks most useful for in data validation? moving data from one field to another hiding parts of a value that are
    9·2 answers
  • What is the datapath of add instruction?
    6·1 answer
  • In which of the following situations would it be most appropriate to choose lossy compression over lossless compression?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!