In: Computer Science
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.
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