Question

# Question 2 for HW 3 use MPLAB IDE # Your solution should implement the following...

# Question 2 for HW 3 use MPLAB IDE
# Your solution should implement the following loop:
#   for (i = 0; i < X; i++) {
#       A = A + X;
#       B = B - X;
#       if (A == B)
#           break;        ## break exits loop early
#   }

        
    .global    main
    .data

### THESE VARIABLES ARE SIMPLY GIVEN VALUES TO START
###   WITH--CHANGE THEIR VALUES AND VERIFY YOUR PROGRAM
###   WORKS APPROPRIATELY IN ALL CASES
A:  .int    1
B:  .int    100
X:  .int    20
        
    .text
    .set       noreorder
    .ent       main

main:
    # Load variables into registers
    lw  $t0, A
    lw  $t1, B
    lw  $t2, X
    
    # Implement loop described above
    # Make sure final values for A and B are in memory
    #   (but you don't necessarily have to update memory
    #    in every loop iteration)
        
# This code simply loops infinitely
spin:   
    j          spin
    nop

    .end        main 

Homework Answers

Answer #1

Tge required code is as below

        
    .global    main
    .data

### THESE VARIABLES ARE SIMPLY GIVEN VALUES TO START
###   WITH--CHANGE THEIR VALUES AND VERIFY YOUR PROGRAM
###   WORKS APPROPRIATELY IN ALL CASES
A:  .int    1
B:  .int    100
X:  .int    20
        
    .text
    .set       noreorder
    .ent       main

main:
    # Load variables into registers
    lw  $t0, A

    lw  $t1, B

    lw  $t2, X 

move $t3,$0  #i =0

    l1: bge $t3,$t2,done  # for condition
        
      add $t0,$t0,$t2  # A =A+X
       sub $t1,$t1,$t2  #B =B-X 
       beq $t0,$t1,done # if A=B exit for
       addi $t3,$t3,1  #i++ 

    j          l1
​​​​

    nop
done:

# store variables from registers

sw $t0, A

sw $t1, B

sw $t2, X

   
    .end        main 
Know the answer?
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
Similar Questions
Section 2: Using the MARS or SPIM simulator develop a program that will implement the following...
Section 2: Using the MARS or SPIM simulator develop a program that will implement the following conditional statement. If ( n is even) { n = n / 2; } else { n = 3 * n + 1; } In this case, n is to be input by the user (assume they input a non-negative value), the conditional is performed, and the resulting n is to be output. Again, use the system calls for input, output, and exiting the...
in C++ Please and thanks Here is a list of 6 numbers. Use the selection sort...
in C++ Please and thanks Here is a list of 6 numbers. Use the selection sort algorithm to sort this list. Fill in this table with each iteration of the loop in the selection sort algorithm. Mark the place from which you are looking for the 'next smallest element'. In this display, the upper numbers are the indices, the lower numbers are in the corresponding positions. Use the several rows provided to show the sequence of steps. 0 1 2...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class Food {     static int count;     private String flavor = "sweet";     Food() { count++; }     void setFlavor(String s) { flavor = s; }     String getFlavor() { return flavor; }     static public void main(String[] args) {         Food pepper = new Food();         System.out.println(pepper.getFlavor());     } } a. a class variable b. a constructor c. a local object variable d....
Consider the C program (twoupdate) to demonstrate race condition. In this assignment, we will implement Peterson's...
Consider the C program (twoupdate) to demonstrate race condition. In this assignment, we will implement Peterson's algorithm to ensure mutual exclusion in the respective critical sections of the two processes, and thereby eliminate the race condition. In order to implement Peterson's Algorithm, the two processes should share a boolean array calledflagwith two components and an integer variable called turn, all initialized suitably. We will create and access these shared variables using UNIX system calls relating to shared memory – shmget,...
#include <stdio.h> #pragma warning(disable : 4996) // CSE 240 Fall 2016 Homework 2 Question 3 (25...
#include <stdio.h> #pragma warning(disable : 4996) // CSE 240 Fall 2016 Homework 2 Question 3 (25 points) // Note: You may notice some warnings for variables when you compile in GCC, that is okay. #define macro_1(x) ((x > 0) ? x : 0) #define macro_2(a, b) (3*a - 3*b*b + 4*a * b - a*b * 10) int function_1(int a, int b) { return (3*a - 3*b*b + 4*a * b - a*b * 10); } // Part 1: //...
1) Consider the following Java program. Which statement updates the appearance of a button? import java.awt.event.*;...
1) Consider the following Java program. Which statement updates the appearance of a button? import java.awt.event.*; import javax.swing.*; public class Clicker extends JFrame implements ActionListener {     int count;     JButton button;     Clicker() {         super("Click Me");         button = new JButton(String.valueOf(count));         add(button);         button.addActionListener(this);         setSize(200,100);         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);         setVisible(true);     }     public void actionPerformed(ActionEvent e) {         count++;         button.setText(String.valueOf(count));     }     public static void main(String[] args) { new Clicker(); } } a. add(button);...
Complete this in C++ and explain what is being done. 1      Introduction The functions in the...
Complete this in C++ and explain what is being done. 1      Introduction The functions in the following subsections can all go in one big file called pointerpractice.cpp. 1.1     Basics Write a function, int square 1(int∗ p), that takes a pointer to an int and returns the square of the int that it points to. Write a function, void square 2(int∗ p), that takes a pointer to an int and replaces that int (the one pointed to by p) with its...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the codes below. Requirement: Goals for This Project:  Using class to model Abstract Data Type  OOP-Data Encapsulation You are asked to write an app to keep track of a relatively small music library. The app should load song information from a data file once the app is started. It should allow user to view, add, remove, and search for songs. The app should...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT