Question

In: Computer Science

Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product...

Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product and quotient without using the multiplication and division instructions. Each input number will be entered on a separate line. Your program will terminate when two zeroes are entered by the user. If only the second number in a pair is zero, then a divide-by-zero error message should be printed for the division operation. Use comments generously in your program. Test your program with the following sets of values:

18 6
16 5
5 11
21 4
2 16
17 2
0 10
10 0
20 5
6 6
0 0

Hand in the program with output.

Solutions

Expert Solution

str1: .asciiz "Enter a: "

str2: .asciiz "Enter b: "

str3: .asciiz "a/b = "

str4: .asciiz "a%b = "

str5: .asciiz "a*b = "

newline: .asciiz "\n"

.text

main: li   $v0, 4           

la   $a0, str1        

syscall               

li   $v0, 5           

syscall               

add $s0, $v0, $zero  

li   $v0, 4           

la   $a0, str2        

syscall  

            

li $v0, 5     

syscall        

move $s1, $v0      

#DO THE CALCULATIONS

div $s0, $s1       

mflo    $t0        

mfhi    $t1        

mult $s0, $s1

mflo $t2

li $v0,1

move $a0, $t2

syscall

li $v0,4

la $a0, str5

syscall

li   $v0, 4           

la   $a0, str3        

syscall               

#print a/b

li $v0, 1     

move $a0, $t0     

syscall

li $v0, 4

    la $a0, str4

    syscall

li $v0, 1

move $a0, $t1

syscall

li $v0, 10    

syscall


Related Solutions

Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product...
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product and quotient without using the multiplication and division instructions. Each input number will be entered on a separate line. Your program will terminate when two zeroes are entered by the user. If only the second number in a pair is zero, then a divide-by-zero error message should be printed for the division operation. Use comments generously in your program. Test your program with the...
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product...
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product and quotient without using the multiplication and division instructions. Each input number will be entered on a separate line. Your program will terminate when two zeroes are entered by the user. If only the second number in a pair is zero, then a divide-by-zero error message should be printed for the division operation. Use comments generously in your program. Test your program with the...
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product...
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product and quotient without using the multiplication and division instructions. Each input number will be entered on a separate line. Your program will terminate when two zeroes are entered by the user. If only the second number in a pair is zero, then a divide-by-zero error message should be printed for the division operation. Use comments generously in your program. Test your program with the...
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...
Write a mips assembly language program to ask the user to enter two integers A and...
Write a mips assembly language program to ask the user to enter two integers A and B and then display the result of computing the expression: A + 2B - 5.
Write MIPs program that will read two integers from the user and compute for the sum...
Write MIPs program that will read two integers from the user and compute for the sum and difference of the two integers. Ask the user whether he wants to repeat the program : "[Y/y] / [N/n] ?".
Assignment Description: Write a MIPS assembly language program that adds the following two integers and displays...
Assignment Description: Write a MIPS assembly language program that adds the following two integers and displays the sum and the difference. In the .data section, define two variables num1 and num2 both words. Initialize num1 to 92413 10 and num2 to D4B 16 (use 0xD4B to initialize, Note that D4B is a hexadecimal number). Your main procedure/function should load the values of num1 and num2 into two temporary registers, and display them on the console window. Then add the values...
Write a MIPS assembly program that prompts the user for some number of cents (integer) and...
Write a MIPS assembly program that prompts the user for some number of cents (integer) and read the user input. Then translate that number of into a number of quarters, dimes, nickels and pennies (all integers) equal to that amount and outputs the result. The output should adequately tell the user what is being output (not just the numeric results).
Write a mips assembly code program that ask the user to enter an integer value, and...
Write a mips assembly code program that ask the user to enter an integer value, and then print the result of doubling that number.
Write a MIPS assembly program that prompts the user for some number of cents (integer) and...
Write a MIPS assembly program that prompts the user for some number of cents (integer) and read the user input. Then translate that number of into a number of quarters, dimes, nickels and pennies (all integers) equal to that amount and outputs the result. The output should adequately tell the user what is being output (not just the numeric results). (Make sure you use comments next to each line to describe what actions you are taking in your code. )...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT