Question

In Assembly - Call Mul from a procedure Create a procedure, and in that procedure multiply...

In Assembly

- Call Mul from a procedure Create a procedure, and in that procedure multiply two numbers together using mul. Then call the procedure from the main procedure.

- Do bitwise mulitiplication using only shift and add statements In your multiplication procedure multiply two numbers not using mul but by combining a fixed number of shift and add commands. For this part you only need to be able to handle 8 bit numbers so you don't need to use a loop for this part

- Add loop to bitwise multiplication procedure Instead of using a fixed number of bitwise multipliers, use a loop to run the bitwise multiplication

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

CODE:

public int mul(int a, int b) {

    if (a ==0 || b == 0) {

        return 0;

    }

    if (a == 1) {

        return b;

    }

    else

        if (b == 1) {

            return a;

        }

    int result = 0;

    int x = a;

    boolean isORNeeded = false;

    while (b != 0 ) {

        if (b == 1) {

            break;

        }

        if ((b & 1) == 1) //......... Carry needed, odd number.........

         {

                 result += x;

            isORNeeded = true;

        }

        a <<= 1; // this will Doubles the a

        b >>= 1; // this will make Half of the b

        System.out.println("a=["+a+"], b=["+b+"], result=["+result+"]");

    }

    return (isORNeeded ? (a | x) : a); // a + result;

}

Add a comment
Know the answer?
Add Answer to:
In Assembly - Call Mul from a procedure Create a procedure, and in that procedure multiply...
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
  • Using MASM Please! Part 1: Call Mul from a procedure (50 pts) Create a procedure, and in that pro...

    Using MASM Please! Part 1: Call Mul from a procedure (50 pts) Create a procedure, and in that procedure multiply two numbers together using mul. Then call the procedure from the main procedure. Part 2: Do bitwise mulitiplication using only shift and add statements (30 pts) In your multiplication procedure multiply two numbers not using mul but by combining a fixed number of shift and add commands. For this part you only need to be able to handle 8 bit...

  • Can someone carefully explain and answer questions 1, 2, 3, 4 and 5 in detail, please!!! Multiplication can be thought...

    Can someone carefully explain and answer questions 1, 2, 3, 4 and 5 in detail, please!!! Multiplication can be thought of as repeated addition. Three times four is 4 added to itself 3 times. 1) Create an assembly program that multiplies two 8 bit integers (2's complement) together in your PIC, using the repeated summation technique 2) Add a feature to your program that detects if the answer is too big to hold in 8 bit 2's complement notation 3)...

  • Can someone carefully explain and answer questions 1, 2, 3, 4 and 5 in detail, please!!!...

    Can someone carefully explain and answer questions 1, 2, 3, 4 and 5 in detail, please!!! Multiplication can be thought of as repeated addition. Three times four is 4 added to itself 3 times. 1) Create an assembly program that multiplies two 8 bit integers (2's complement) together in your PIC, using the repeated summation technique 2) Add a feature to your program that detects if the answer is too big to hold in 8 bit 2's complement notation 3)...

  • First you must create a logic circuit using only basic gates such as AND, OR, NOR,...

    First you must create a logic circuit using only basic gates such as AND, OR, NOR, NAND, NOT, etc. to implement an ADDER capable of adding two 4 bit binary numbers. Second you must create a logic circuit using only basic gates such as AND, OR, NOR, NAND, NOT, etc. to implement a Subtractor that is capable of subtracting the second number from the first, by converting the second number into its 2's complement form and then adding the resulting...

  • Use Assembly (Masm and Irvine32 library) to write a complete program that: 1. Asks the user...

    Use Assembly (Masm and Irvine32 library) to write a complete program that: 1. Asks the user to enter 2 numbers. Assume that the user enters unsigned 32-bit integers only. 2. Displays the product of the two numbers. Assume that the result will never be larger than 32 bits. 3. This process will continue till the user enters 0 for both inputs. You can’t use mul instruction in your program: You need to use shifting and addition only. Your program must...

  • A shift operation is often used to implement either multiply-by-power-of-2 or divide-by power-of-...

    A shift operation is often used to implement either multiply-by-power-of-2 or divide-by power-of-2 operations. For example, 0010 x4 1000. This multiplication can be achieved by shifting 0010 by 2 bits to the left. Likewise, 10004 0010, which can be obtained by shifting 1000 to the right by 2 bits. As multipliers are more "expensive" in terms of area and power consumption, multiplication by shifting is preferred if applicable. Sometime, the multiplier does not have to be power-of-2. For example, 0010...

  • Write MIPS code for each of the following instructions, Your assembly should implement the C code...

    Write MIPS code for each of the following instructions, Your assembly should implement the C code directly – i.e.,do not ’optimize’ the C code to change the order of operations or reduce computations. Use commands only like add, sub, lw, sw, immediate Part 1. x = 3-13*x; Do not use multiply. One way of doing the multiply without a multiply instruction is by using many add instructions (x+x+...+x). For this problem, you should do it with fewer additions. Hint: We...

  • 1. Suppose you found your dream job working on an 8-bit computer/microcontroller and working with assembly...

    1. Suppose you found your dream job working on an 8-bit computer/microcontroller and working with assembly (which includes writing assembly from scratch). Also, suppose your project manager wants the 8-bit processor to able to handle fixed-point arithmetic operations that include addition, subtraction, and multiplication. Assume you can perform division with the combination of previously mentioned instructions. The fixed-point number representation is eight bits and would need to represent numbers between -2d = 1000 0000 And Max number = 0111 1111...

  • Create a procedure driven program for performing arithmetic with fractions. Using a switch statement in main...

    Create a procedure driven program for performing arithmetic with fractions. Using a switch statement in main to perform the various actions. Similar to this; Menu a) Load/Reload first fraction b) Load/Reload second fraction c) Add two fractions and display answer d) Subtract two fractions and display answer e) Multiply two fractions and display answer f) Divide two fractions and display answer g) Exit Provide functions that allow for The reloading of the fractions. The addition of two rational numbers. The...

  • Python Help Create a program that outputs a table from 1 to 5 using what you've...

    Python Help Create a program that outputs a table from 1 to 5 using what you've learned about "for" loops. Your program will print the number and indicate if the number is odd or even. If it is not odd you will multiply 2 numbers with it: number 1 and number 2. Your program must do the multiplication for only even numbers in the table. The output of your program should look like the figure below. Hint: Create a program...

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