Question

Write a MIPS assembly language procedure that simulates/implements the multiplication of two unsigned integers. The procedure...

Write a MIPS assembly language procedure that simulates/implements the multiplication of two unsigned integers. The procedure receives the mulitiplicand and the multiplier and returns the product. IT CANNOT USE A MULTIPLY INSTRUCTION! Write a MIPS assembly language program that demonstrates your multiplication procedure. Your program should ask the user for two integers to multiply. You can assume that the input integers are positive. Adhere to the procedure call convention.

Homework Answers

Answer #1

Lines of procedure without using Mult function:

.data

promptStart: .asciiz "This prrogram does AxB without using mult"
getA: .asciiz "Please enter the first number(multiplicand): "
getB: .asciiz "Please enter the second number(multiplier): "

space: .asciiz " "

result: .asciiz "The product, using my program is: "
endLine: .asciiz "\n"
.text
main:
#"welcome" screen
li $v0,4 # code for print_string
la $a0,promptStart # point $a0 to prompt string
syscall # print the prompt

li $v0,4 # code for print_string
la $a0,endLine # point $a0 to prompt string
syscall # print the prompt

#prompt for multiplicand
li $v0,4 # code for print_string
la $a0,getA # point $a0 to prompt string
syscall # print the prompt

#acquire multiplicand
li $v0,5 # code for read_int
syscall # get an int from user --> returned in $v0
move $s0,$v0 # move the resulting int to $s0

move $s4,$s0 #copy of multiplicand to use in multu

#prompt for multiplier
li $v0,4 # code for print_string
la $a0,getB # point $a0 to prompt string
syscall # print the prompt

#acquire multiplier
li $v0,5 # code for read_int
syscall # get an int from user --> returned in $v0
move $s1,$v0 # move the resulting int to $s0

move $s5,$s1 #copy of multiplier to use in multu

jal MyMult
j print

MyMult:
#$s2 -> lw product, $s1 -> hw multiplier, $s0 -> multiplicand
beq $s1, $0, done # if multiplier=0--> mult gives 0
beq $s0, $0, done
move $t0, $0 #initialize 'counter'= 31
add $t0, $t0, 31
move $s2, $0 #initialize product = 0

loopOut:
beq $t0, $0, done #loop check

andi $t1, $s1, 1 #Stores LSB(MSB?) of $s1 in $t1
bne $t1, $0, loopIn #check if LSB is equal to 1
srl $s1, $s1, 1
srl $s2, $s2, 1 #right shift product & multiplier
add $t0, $t0,-1 # counter = counter -1
j loopOut

loopIn:
addu $s2, $s2, $s0 #Lw product($s2/$s1)+= multiplicand($s0)
sltu $t2, $s2, $s0 #catch carry-out(0 or 1) and stores in $t2

srl $s1, $s1, 1
srl $s2, $s2, 1 #right shift pro-plier..how to save LSB of $s2?

#add carry-out $t2 to LSB of product $s2
addu $s2, $s2, $t0 #Is this right?

addu $t0, $t0,-1 # counter = counter -1
j loopOut

done:
jr $ra

print:
# print result string
li $v0,4 # code for print_string
la $a0,result # point $a0 to string
syscall # print the result string

# print out the result
li $v0,1 # code for print_int
move $a0,$s2 # put result in $a0
syscall # print out result

li $v0,4 # code for print_string
la $a0,space # point $a0 to string
syscall # print the result string

li $v0,1 # code for print_int
move $a0,$s1 # put result in $a0
syscall # print out result


# print the line feed
li $v0,4 # code for print_string
la $a0,endLine # point $a0 to string
syscall # print the linefeed

I hope you got your answer.

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
(MIPS Assembly language) Ask user for two decimal numbers and save to memory (not registers). Multiply...
(MIPS Assembly language) Ask user for two decimal numbers and save to memory (not registers). Multiply these two numbers using adding and shifting only, not the "mul" instruction and print the product to the user as both a base-10 and base-32 (again, no using div/mul/rem). Save the output to a txt file. The program should run 5 times, with no user input needed to continue the program.    
Write a mips assembly language program that asks the user to enter and integer number and...
Write a mips assembly language program that asks the user to enter and integer number and read it. Then ask him to enter a bit position (between 0 and 31) and display the value of that bit.
Use MARS to write and simulate a MIPS assembly language program to swap two of the...
Use MARS to write and simulate a MIPS assembly language program to swap two of the integers in an integer array. The program should include the Swap function to swap the integers and the main function to call the Swap function. Download the template file “P4_template.asm” provided on Blackboard. Add your code to this file. Do not modify any of the code provided in the file. The main function should: • Pass the starting address of the array in $a0....
write a MIPS assembly program to get an integer input from the user and multiply it...
write a MIPS assembly program to get an integer input from the user and multiply it by 2 and print output to the console
Write a program in MIPS ASSEMBLY LANGUAGE.. Take no of students as input from the user,...
Write a program in MIPS ASSEMBLY LANGUAGE.. Take no of students as input from the user, then take marks of 5 subjects for each student from the user. Then find Minimun, Maximum and Median of all the subjects. and comment each line in code also make flow chart
Write a MIPS Assembly Language program to request a name and reflect it back to the...
Write a MIPS Assembly Language program to request a name and reflect it back to the user. The request must be "Please enter your full name:" And it should be output following "The name you entered was: '
Write a program in Mars MIPS Assembly Language that asks the user for an 8-digit hexadecimal...
Write a program in Mars MIPS Assembly Language that asks the user for an 8-digit hexadecimal and then prints out its 32-bit binary representation, the operation of the function, the format (I, R, or J), the fields associated with the format (op, rs, rt, imm, shamt, funct), and the instruction associated with the hexadecimal. All five parts must be written as functions.
Using Windows 32 framework , write an assembly language program; Write a recursive procedure to find...
Using Windows 32 framework , write an assembly language program; Write a recursive procedure to find the greatest common divisor of two non negative numbers. You should use Euclidean algorithm and this is typically discussed in CSC 230. Your procedure: ❼ Needs to follow cdecl protocol. ❼ Needs to take two parameters. ❼ Should return -1, if the parameters are negative. ❼ Should return gcd, if the parameters are non negative. Your main procedure should do the followings. ❼ Read...
In x86-64 Windows Assembly Language. Program that adds two unsigned integer values and produces formatted console...
In x86-64 Windows Assembly Language. Program that adds two unsigned integer values and produces formatted console output using the 'C' library function printf(). The two unsigned integer values are input by the user from the keyboard at runtime using the 'C' library function scanf().
Use MIPS assembly language program to swap two of the integers in an integer array. The...
Use MIPS assembly language program to swap two of the integers in an integer array. The program should include the Swap function to swap the integers and the main function to call the Swap function. The main function should: • Pass the starting address of the array in $a0. • Pass the indices of the two elements to swap in $a1 and $a2. • Preserve (i.e. push onto the stack) any T registers that it uses. • Call the Swap...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT