in Education by
I have to write in MIPS a program that multiplies two number using the add and shift method. After trying many many times, I got somehow a program that I see to should be working, but its not, then I wrote it in Java and the code worked in Java. Then I tried to convert it from Java to MIPS (usually its easier for me to translate to low level language from a code in high level language), and after translating it, still its not working. Here is the code I wrote, and please if anybody detects anything wrong with them or knows how to fix them please do tell me. Thanks, In Java: static int prod = 0; public static int mult (int mcand, int mier) { while (mier != 0) { int rem = mier % 2; if (rem != 0) { prod += mcand; } mcand = mcand << 1; mier = mier >> 1; } return prod; } In MIPS: # A program that multiplies two integers using the add and shift method .data # Data declaration section .text main: # Start of code section li $s0, 72 # the multiplicand li $t0, 72 # the multiplicand in a temporary register li $s1, 4 # the multiplier li $t1, 4 # the multiplier in a temporary register li $s2, 0 # the product li $s3, 2 # the number 2 in a register for dividing by 2 always for checking if even or odd LOOP: # first we check if the multiplier is zero or not beq $t1, $zero, END div $t1, $s3 mfhi $t3 # remainder is now in register $t3 beq $t3, $zero, CONTINUE # if the current digit is 0, then no need to add just go the shifting part add $s2, $s2, $t0 # the adding of the multiplicand to the product CONTINUE: # to do the shifting after either adding or not the multiplicand to the product sll $t0, $t0, 1 srl $t0, $t0, 1 j LOOP # to jump back to the start of the loop END: add $a0, $a0, $s2 li $v0, 1 syscall # END OF PROGRAM JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Copy error on srl at the end: srl $t1, $t1, 1

Related questions

0 votes
    Using tJavaFlex how many parts of java-code you can add in your Job? One Two Three Four...
asked Mar 25, 2021 in Technology by JackTerrance
0 votes
    I am attempting to devise a system for packing integer values greater than 65535 into a ushort. Let me ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    I am attempting to devise a system for packing integer values greater than 65535 into a ushort. Let me ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    ________ is used for translating between qplot and base graphics. (a) translate_qplot_base (b) translate_qplot_gpl (c ... R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    I'm building a C++/MFC program in a multilingual environment. I have one main (national) language ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 25, 2022 in Education by JackTerrance
0 votes
    I'm building a C++/MFC program in a multilingual environment. I have one main (national) language ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 24, 2022 in Education by JackTerrance
0 votes
    I want to load an image from my computer into 2D Graphics so that I can edit it afterwards and ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
0 votes
    write a C program to Read a number.Find sum of digit at even position in a number and multiplication of digit ... position in a number. Select the correct answer from above options...
asked Dec 13, 2021 in Education by JackTerrance
0 votes
    Is there any efficient and portable way to check when multiplication operations with int64_t or uint64_t operands ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    Is there any efficient and portable way to check when multiplication operations with int64_t or uint64_t operands ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    I want to multiply these two matrices using pure python. Input (M1 is 3*3 and Mt is a 3*2) M1 = ... But technically this should work. Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    Perform Binary Multiplication: 101010*1011 * O. 111001100 O 101001101 O 111001110 Select the correct answer from above options...
asked Dec 31, 2021 in Education by JackTerrance
0 votes
    Perform Binary Multiplication: 101010*1011 * 111001100 0 101001101 O 111001110 Select the correct answer from above options...
asked Dec 31, 2021 in Education by JackTerrance
0 votes
    Perform Binary Multiplication: 101010*1011 * 111001100 O 101001101 O 111001110 Select the correct answer from above options...
asked Dec 31, 2021 in Education by JackTerrance
0 votes
    1. Use the multiplication method to find the total number of different combinations possible for a case-sensitive ... be repeated. Select the correct answer from above options...
asked Dec 20, 2021 in Education by JackTerrance
...