Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is written in MIPS assembly language on MARS 4.5. Only allowed to use the o

ID: 3594536 • Letter: T

Question

This is written in MIPS assembly language on MARS 4.5.

Only allowed to use the operands of addition and subtraction. No multiplication, division or shift operands allowed.

Here is my code, but there is a problem, everytime i try to divide by zero, the program won't run. If i try to divide the same number, the program won't run. If i try to divide by a number higher than the denominator, it has a negative modulus. How do I write the code to not include negative numbers, and when dividing by 0, give the answer 0.

here's my code:

.data
Prompt: .asciiz "Enter 2 integers for f and g respectively: "
newLine: .asciiz " "
message1: .asciiz " h_quotient = "
message2: .asciiz " h_remainder = "
message3: .asciiz " i_mod = "
.text

main:
li $v0, 4
la $a0, Prompt
syscall

# Read input f in $v0 and store in $t0
li $v0, 5
syscall
move $t0, $v0

# Read input g in $v0 and store in $t1

li $v0, 5
syscall
move $t1, $v0

#Loop1
move $t3, $t0
li $t2, 0
Loop1:
blt $t3, $t1, Exit1
sub $t3, $t3, $t1
addi $t2, $t2, 1
j Loop1
Exit1:

sub $t6, $t0, $t1

#Loop2
move $t4, $t6
li $t5, 0
Loop2:
blt $t4, $t3, Exit2
sub $t4, $t4, $t3
addi $t5, $t5, 1
j Loop2
Exit2:

# Print message1
li $v0, 4
la $a0, message1
syscall

# Print integer in decimal
li $v0, 1
move $a0, $t2
syscall

li $v0, 4
la $a0, newLine
syscall

# Print message2
li $v0, 4
la $a0, message2
syscall

# Print integer in decimal
li $v0, 1
move $a0, $t3
syscall

li $v0, 4
la $a0, newLine
syscall

# Print message3
li $v0, 4
la $a0, message3
syscall

# Print integer in decimal
li $v0, 1
move $a0, $t4
syscall

li $v0, 4
la $a0, newLine
syscall

#end the program
li $v0, 10
syscall

h = f/g; i-(f-g) MOD h remainder: More formally, write MIPS code to output the result of above expression ofh and i without using any built-in MIPS/MARS instructions for multiplication or division. The values already entered for Part A for a, b, c, and d shall be used. Output the value of h and i in {quotient with remainder] in a format as separate decimal integers. Indicate the denominator for the remainder.

Explanation / Answer

The updated code :

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote