Question

Here is the finsihed java program, it just needs to be converted to MIPs assembly language:...

Here is the finsihed java program, it just needs to be converted to MIPs assembly language:

import java.util.*;

public class LoveCS {

public static void main(String[] args) {

int timesMessagePrinted;

int count = 0;

int sum = 0;

Scanner input = new Scanner(System.in);

System.out.print("How many times should the message be printed?: ");

timesMessagePrinted = input.nextInt();

for(int x = 1; x <= timesMessagePrinted; x++) {

System.out.println(x +" I love Computer Science!!");

count++; sum += x;

}

System.out.print("Printed this message " +count + " times. The sum of the numbers from 1 to " + count + " is " + sum + ". \n");

}

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

In MIPS GCC 5.4 the code will look like this:

$Ltext0:

$LC0:

.ascii "How many times should the message be printed?: \000"

$LC1:

.ascii "%d\000"

$LC2:

.ascii "%d I love Computer Science!!\012\000"

$LC3:

.ascii "Printed this message %d times. The sum of the numbers fr"

.ascii "om 1 to %d is %d \012\000"

$LFB0 = .

main:

addiu $sp,$sp,-48

sw $31,44($sp)

sw $fp,40($sp)

move $fp,$sp

sw $0,24($fp)

sw $0,28($fp)

lui $2,%hi($LC0)

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

jal printf

nop

addiu $2,$fp,36

move $5,$2

lui $2,%hi($LC1)

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

jal scanf

nop

$LBB2 = .

li $2,1 # 0x1

sw $2,32($fp)

$L3:

lw $2,36($fp)

lw $3,32($fp)

nop

slt $2,$2,$3

bne $2,$0,$L2

nop

lw $5,32($fp)

lui $2,%hi($LC2)

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

jal printf

nop

lw $2,24($fp)

nop

addiu $2,$2,1

sw $2,24($fp)

lw $3,28($fp)

lw $2,32($fp)

nop

addu $2,$3,$2

sw $2,28($fp)

lw $7,28($fp)

lw $6,24($fp)

lw $5,24($fp)

lui $2,%hi($LC3)

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

jal printf

nop

lw $2,32($fp)

nop

addiu $2,$2,1

sw $2,32($fp)

b $L3

nop

$L2:

$LBE2 = .

move $2,$0

move $sp,$fp

lw $31,44($sp)

lw $fp,40($sp)

addiu $sp,$sp,48

j $31

nop

$LFE0:

$Letext0:

$Ldebug_info0:

$Ldebug_abbrev0:

$Ldebug_line0:

$LASF6:

$LASF0:

$LASF15:

$LASF3:

$LASF7:

$LASF14:

$LASF13:

$LASF10:

$LASF1:

$LASF16:

$LASF12:

$LASF8:

$LASF2:

$LASF4:

$LASF5:

$LASF11:

$LASF9:

In *86-64 GCC 9.2 the code will look like this:

.LC0:
        .string "How many times should the message be printed?: "
.LC1:
        .string "%d"
.LC2:
        .string "%d I love Computer Science!!\n"
.LC3:
        .string "Printed this message %d times. The sum of the numbers from 1 to %d is %d \n"
main:
        push    rbp
        mov     rbp, rsp
        sub     rsp, 16
        mov     DWORD PTR [rbp-4], 0
        mov     DWORD PTR [rbp-8], 0
        mov     edi, OFFSET FLAT:.LC0
        mov     eax, 0
        call    printf
        lea     rax, [rbp-16]
        mov     rsi, rax
        mov     edi, OFFSET FLAT:.LC1
        mov     eax, 0
        call    scanf
        mov     DWORD PTR [rbp-12], 1
.L3:
        mov     eax, DWORD PTR [rbp-16]
        cmp     DWORD PTR [rbp-12], eax
        jg      .L2
        mov     eax, DWORD PTR [rbp-12]
        mov     esi, eax
        mov     edi, OFFSET FLAT:.LC2
        mov     eax, 0
        call    printf
        add     DWORD PTR [rbp-4], 1
        mov     eax, DWORD PTR [rbp-12]
        add     DWORD PTR [rbp-8], eax
        mov     ecx, DWORD PTR [rbp-8]
        mov     edx, DWORD PTR [rbp-4]
        mov     eax, DWORD PTR [rbp-4]
        mov     esi, eax
        mov     edi, OFFSET FLAT:.LC3
        mov     eax, 0
        call    printf
        add     DWORD PTR [rbp-12], 1
        jmp     .L3
.L2:
        mov     eax, 0
        leave
        ret

Add a comment
Know the answer?
Add Answer to:
Here is the finsihed java program, it just needs to be converted to MIPs assembly language:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need to write a program in java that reads a text file with a list...

    I need to write a program in java that reads a text file with a list of numbers and sorts them from least to greatest. This is the starter file. import java.util.*; import java.io.*; public class Lab3 { static final int INITIAL_CAPACITY = 5; public static void main( String args[] ) throws Exception { // ALWAYS TEST FOR REQUIRED INPUT FILE NAME ON THE COMMAND LINE if (args.length < 1 ) { System.out.println("\nusage: C:\\> java Lab3 L3input.txt\n"); System.exit(0); } //...

  • DEBUGGING. JAVA. Identify the errors in the following. There are no logical errors in this one...

    DEBUGGING. JAVA. Identify the errors in the following. There are no logical errors in this one just syntax issues. //start import java.util.Scanner; public class NumbersDemo {    public static void main (String args[])    {       Scanner kb = new Scanner(System.in);       int num1, num2;             System.out.print("Enter an integer >> ");       num1 = kb.nextInt();       System.out.print("Enter another integer >> ");       num2 = kb.nextDouble();       displayTwiceTheNumber(num1);       displayNumberPlusFive(num1);       displayNumberSquared(num1)       displayTwiceTheNumber(num2);       displayNumberPlusFive(num2);       displayNumberSquared(num2);    }   ...

  • Change the following Shift Cipher program so that it uses OOP(constructor, ect.) import java.util...

    Change the following Shift Cipher program so that it uses OOP(constructor, ect.) import java.util.*; import java.lang.*; /** * * @author STEP */ public class ShiftCipher { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Scanner input = new Scanner(System.in); String plainText; System.out.print("Please enter your string: "); // get message plainText = input.nextLine(); System.out.print("Please enter your shift cipher key: "); // get s int s = input.nextInt(); int...

  • Finish the given ProcessFile.java program that prompts the user for a filename and reprompts if file...

    Finish the given ProcessFile.java program that prompts the user for a filename and reprompts if file doesn’t exist. You will process through the file skipping any text or real (double) numbers. You will print the max, min, sum, count, and average of the integers in the file. You will want to create test files that contain integers, doubles, and Strings. HINT: Use hasNextInt() method and while loop. You may also want to use Integer.MAX_VALUE and Integer.MIN_VALUE for the initialization of...

  • in java, my IF statement is being ignored & my print statement won't work..why? Start Page xIẾ》 Smallestintege...

    in java, my IF statement is being ignored & my print statement won't work..why? Start Page xIẾ》 Smallestinteger.java x 1|曰import java.util. Scanner; 3public class SmallestInteger i public static void main (String[] args) i Scanner input - new Scanner (System.in); int lowValue0 int nextöne; 10 int counter: 12 System.out.print ("How many integers?" 13 int index = input .next Int ( ) ; 14 15 for (counter=1; counter index -counter){ 16 System.out.print ("Enter integer, please: "); 17 nextOne - input.nextInt ) 18...

  • JAVA HELP: Directions Write a program that will create an array of random numbers and output...

    JAVA HELP: Directions Write a program that will create an array of random numbers and output the values. Then output the values in the array backwards. Here is my code, I am having a problem with the second method. import java.util.Scanner; import java.util.Random; public class ArrayBackwards { public static void main(String[] args) { genrate(); print(); } public static void generate() { Scanner scanner = new Scanner(System.in);    System.out.println("Seed:"); int seed = scanner.nextInt();    System.out.println("Length"); int length = scanner.nextInt(); Random random...

  • Looking for some simple descriptive pseudocode for this short Java program (example italicized in bold directly...

    Looking for some simple descriptive pseudocode for this short Java program (example italicized in bold directly below): //Create public class count public class Count {     public static void main(String args[])     {         int n = getInt("Please enter an integer value greater than or equal to 0");                System.out.println("Should count down to 1");         countDown(n);                System.out.println();         System.out.println("Should count up from 1");         countUp(n);     }            private static void countUp(int n)     {...

  • How would you write the following program using switch statements instead of if-else statements (in java)...

    How would you write the following program using switch statements instead of if-else statements (in java) import java.util.*; public class ATM { public static void main(String[] args) { Scanner input = new Scanner (System.in); double deposit, withdrawal; double balance = 6985.00; //The initial balance int transaction; System.out.println ("Welcome! Enter the number of your transaction."); System.out.println ("Withdraw cash: 1"); System.out.println ("Make a Deposit: 2"); System.out.println ("Check your balance: 3"); System.out.println ("Exit: 4"); System.out.println ("***************"); System.out.print ("Enter Your Transaction Number "); transaction...

  • JAVA Can you make this return the first letter of  first and last name capitalized? import java.io.File;...

    JAVA Can you make this return the first letter of  first and last name capitalized? import java.io.File; import java.io.IOException; import java.util.*; public class M1 {    public static void main(String[] args) {        //scanner input from user    Scanner scanner = new Scanner(System.in); // System.out.print("Please enter your full name: "); String fullname = scanner.nextLine(); //creating a for loop to call first and last name separately int i,k=0; String first="",last=""; for(i=0;i<fullname.length();i++) { char j=fullname.charAt(i); if(j==' ') { k=i; break; } first=first+j;...

  • 5. Write a static method "f(n)" in the space provide, that returns O if n is...

    5. Write a static method "f(n)" in the space provide, that returns O if n is even, and if n is odd, returns 1 or -1 according as n is greater than or less than 0. importjava.util.Scanner; public class Q_05 Your "f(n)" method: public static void main(String args[]) mana int n; Scanner input = new Scanner(System.in); System.out.print("Please enetrn: "); n=input.nextInt(); System.out.println(f(n)); "Method f(n)" 7. Write a static method "max" in the space provide, that returns the maximum value from 3...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT