Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

can anyone help me out in this MIPS language for the following lab please with i

ID: 3573136 • Letter: C

Question

can anyone help me out in this MIPS language for the following lab please with in two days

CSC263 Computer Organization & Architecture I
Lab 4

In this lab you will write a program which implements multiplication in software.

If a computer doesn't have multiplication implemented in hardware then in must be implemented in software. The obvious algorithm to implement a * b is to add a to itself b times:

This algorithm requires b additions.

A more efficient algorithm is to use the one that we learned when we first learned to multiply:

For example, multiply 1732 by 546:

This algorithm is even simpler when multiplying binary numbers, because the digits by which we are multiplying can only be zero or one. thus at each step we either add a (if the digit d is a 1) or not (if the digit d is a 0), For example, multiply 100110 by 1011:

This algorithm requires log b additions (the number of bits in b).

This is the algorithm you will implement in your program. First the program will prompt the user and read the numbers a and b to be multiplied. The program will multiply the numbers as shown above, by adding shifted versions of a. For each digit of b you will need to determine whether it is 0 or 1, because (as shown above) if a digit is 0 then nothing is added for that digit.

Print a copy of your code and demonstrate the execution for me.

Make sure your program includes comments. You need comments at the top with your name and lab number, and comments for every line of executable code.

Explanation / Answer

import java.io.BufferedReader;

import java.io.IOException;
import java.io.InputStreamReader;

public class BinaryMultiplication {

   /**
   *
   */
   public BinaryMultiplication() {
   }

   /**
   * @param args
   * @throws IOException
   */
   public static void main(String[] args) throws IOException {

       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

//Taking input

       String multiplicand = br.readLine();
       String multiplier = br.readLine();
      
       int multiplierLength = multiplier.length();
       String product = "0";
       for(int i=multiplierLength-1;i>=0;i--){

//Checking whether binary digit is 1 or 0

// if 1, it will add to product else skip
           if(Integer.parseInt(""+multiplier.charAt(i))==1){

// adding binay numbers
               product = binaryAddition(product,multiplicand);
               System.out.println(product);
           }

// below statement equals to multiplying by 10 in demical
           multiplicand = multiplicand+"0";
       }
       System.out.println("FInal Product: "+Integer.parseInt(product,2));
   }

// below method will add two biany Strings
   public static String binaryAddition(String s1, String s2) {
   if (s1 == null || s2 == null) return "";
   int first = s1.length() - 1;
   int second = s2.length() - 1;
   StringBuilder sb = new StringBuilder();
   int carry = 0;
   while (first >= 0 || second >= 0) {
   int sum = carry;
   if (first >= 0) {
   sum += s1.charAt(first) - '0';
   first--;
   }
   if (second >= 0) {
   sum += s2.charAt(second) - '0';
   second--;
   }
   carry = sum >> 1;
   sum = sum & 1;
   sb.append(sum == 0 ? '0' : '1');
   }
   if (carry > 0)
   sb.append('1');

   sb.reverse();
   //System.out.println(sb);
   return String.valueOf(sb);
   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote