- #1

- 85

- 0

## Homework Statement

Write a routine that accepts two integers i and j as arguments, calculates the quotient and remainder of i and j, and generates a string in memory that stores "The quotient of i and j is i/j and the remainder is i%j". For example if the arguments was 15 and 7 the string in memory would be "The quotient of 15 and 7 is 2 and the remainder is 1". The address of the string is returned as the 3rd argument of your routine. Write a main program that calls your routine, test run it using MARS and show the output.

## Homework Equations

## The Attempt at a Solution

# division.asm

.data

intI: .asciiz "\nEnter i: "

intJ: .asciiz "\nEnter j: "

quotient: .asciiz "\nThe quotient is = "

remainder: .asciiz "\n\nThe remainder is = "

.text

main: li $v0, 4 # system call code for print_string

la $a0, intI # address of intI

syscall # print intI

#get the first number from user, put it into $s0

li $v0, 5 # system call code for read_int

syscall # read an integer into $v0 from console

add $s0, $v0, $zero # copy $v0 into $s0

#read print_string for str2

li $v0, 4 # system call code for print_string

la $a0, intJ # address of intJ

syscall # print str1

# get second number from user, put it into $t1

li $v0, 5 #load syscall for read_int

syscall #make the syscall

move $s1, $v0 #move the number read into $s1

div $s0, $s1 #diving $s0 by $s1

mflo $t0 #storing value of lo(quotient) in

#register $t0

mfhi $t1 #storing value of hi(remainder) in

#register $t1

mult $s0, $s1

mflo $t2

li $v0, 4 # Print string

la $a0, quotient # address of quotient

syscall

#print a/b

li $v0, 1 #load syscall print_int into $v0

move $a0, $t0 #move the number to print into $t2

syscall

# read print string for remainder

li $v0, 4

la $a0, remainder

syscall

# print remainder

li $v0, 1

move $a0, $t1

syscall

#end of program

li $v0, 10 #system call code for exit

syscall

What I'm having a problem with is the output. I'm not sure how I'm supposed to do "For example if the arguments was 15 and 7 the string in memory would be 'The quotient of 15 and 7 is 2 and the remainder is 1' "

Also am I storing the numbers as strings not integers?