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
  • Write a Java method that should take an ArrayList as a parameter, print its element in...

    Write a Java method that should take an ArrayList as a parameter, print its element in the reverse order. The main function that calls the method is the following: import java.util.*; public class ReverseGen {   public static void main(String[] args) {     Scanner input = new Scanner(System.in);       System.out.println("How many numbers do you want to input?");       int num = input.nextInt();       ArrayList<Double> d = new ArrayList<Double>(num);       for(int i = 0 ; i < num; i++){           System.out.print("Enter...

  • 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); } //...

  • 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...

  • JAVA: Rewrite the following code to where the inputs are from a file. The file name...

    JAVA: Rewrite the following code to where the inputs are from a file. The file name will be from the input from the user scanner. CODE: import java.util.*; public class Q1 { public static int sumOD (int k) { int sumOD = 0; int in = k; while (in != 0) { int digitON = in % 10; sumOD += digitON; in /= 10; } return sumOD; }    public static void main(String[] args) { int n, i, k; System.out.println("Enter...

  • How would I edit this Java program to end if the user inputs 0 or less?...

    How would I edit this Java program to end if the user inputs 0 or less? public static void main(String[] args) { Scanner sc = new Scanner(System.in); // to read input String Message; int m=0; int i=1; System.out.print("Please enter the message you would like displayed: "); Message=sc.nextLine(); while(true) { System.out.print("How many times would you like your message displayed?"); m = sc.nextInt(); break; } do { System.out.println(Message); //When I enter 0 or a negative number it still runs at least once,...

  • 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;...

  • 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...

  • My program will not compile. Recieving an error message: ShoppingBagDemo.java:9: error: cannot find symbol ShoppingBag myBag...

    My program will not compile. Recieving an error message: ShoppingBagDemo.java:9: error: cannot find symbol ShoppingBag myBag = new ShoppingBag(6); ^ symbol: class ShoppingBag location: class ShoppingBagDemo ShoppingBagDemo.java:9: error: cannot find symbol ShoppingBag myBag = new ShoppingBag(6); ^ symbol: class ShoppingBag location: class ShoppingBagDemo 2 errors Here is my code. (Using jGrasp) import java.util.*; class ShoppingBagDemo { public static void main(String[] args) { Scanner sc = new Scanner(System.in); float cost; ShoppingBag myBag = new ShoppingBag(6); System.out.print("Enter count (use 0 to stop):...

  • 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...

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